Hi guys! I am a sysadmin and i want to make tools for my colleagues. I am decent in scripting in powershell, but my javascript knowledge is not so great. I'm trying to make an electron-app with React which is supposed to call a powershell-script(The module im using is Node-powershell). I manage to get this to work if im just using electron, but when i try to implement it with React, several errors pop up:```TypeError: spawn is not a functionnew Shellhttp://localhost:3000/static/js/0.chunk.js:2044:1862 | Object.keys(options).filter(k => !['pwsh', 'pwshPrev', 'debugMsg', 'verbose', 'inputEncoding', 'outputEncoding'].includes(k)).forEach(k => { 63 | psOpts = [...convertToPSOption(k, options[k]), ...psOpts]; 64 | }); > 65 | const proc = spawn("".concat(psProc).concat(!isWin ? '' : '.exe'), psOpts, { | ^ 66 | stdio: 'pipe' 67 | }); 68 | this.pid = proc.pid; // make sure the PS process start successfully ```The code im trying to implement is this: ``` componentDidMount() { let ps = new powershell({ executionPolicy: 'Bypass', noProfile: true })ps.addCommand('Get-Process'); ps.invoke() .then(output => { console.log(output); }) .catch(err => { console.log(err); }) }```My theory is that this does not work because websites are not allowed to start progams on your local computer. If this is correct, is it possible to pass the command to NodeJs somehow?I oroginally posted this in the electronJs subreddit, but the activity in that subreddit seems kinda underwhelming.Appreciate any attempt in trying to help:)
Submitted July 16, 2019 at 02:18PM by Competitive_Mango
No comments:
Post a Comment