-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relative paths to PS scripts on Windows machines #45
Comments
Is your script saved in the .ps1 format? If yes can you try this more basic syntax: ps.addCommand(`./Get-Drives.ps1 -ComputerName ${computerName}`); and if that doesnt work can you please share your version of node, npm, node-powershell, and Windows PowerShell? |
Yes, my script is saved as Get-Drives.ps1 I tried your command and no luck. Also tried it with single quotes and double quotes. I am using node 8.9.4, npm 5.6.0, node-powershell 3.3.0, electron 1.8.2-beta.4 and Windows 7 SP1 64bit. Could I possibly need to add the .ps1 file to my package.json or something? Or format the file location string into a path object for PS? I saw an earlier issue was resolved by using Shell.executionStringBuilder, but I have not been able to find out anything about this. Think its relevant? |
Go to Start > Run > powershell.exe $PSVersionTable.PSVersion what does it say? If powershell.exe is not found maybe you need to install Windows Management Framework (go ahead and use 5.0) or maybe you're using PowerShell Core? There is an issue about pwsh not found and I have a PR open. |
Here is the output for the PSVersion:
I am brand new to Powershell so I will need to do some research on the versions and on the Windows Management Framework. |
Is the error about node-powershell not found? Are you importing node-powershell into your render.js? Could you try the CJS syntax: const powershell = require('node-powershell'); Even better can you share your render.js in its entirety or put the project on github? |
Hello, apologies for the delayed response. I have put my whole example project (called AWMT-electron) onto GitHub. https://github.com/AdamCankaya/AWMT-electron It is a simple webpage with a text link to a JS function that launches a PS script called releaseIP that just calls "ipconfig /release". On renderer.js, lines 11 and 12, you will see my issue. If I use the command on line 11, a direct path to the releaseIP.ps1 file, everything works fine. However, if I comment out line 11, and then run line 12, which tries to call "./releaseIP" then it fails. It gives an error about releaseIP not being found. |
//for example:
{
"name": "awm-app",
"version": "1.0.0",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"dependencies": {
"electron": "^1.8.2",
"jquery": "^3.3.1",
"node-powershell": "^3.3.1"
}
} 3.Note how this package.json also uses symantic versioning (1.0 is invalid 1.0.0 is valid) All that stuff aside, this worked for me first try with the command on line 12 not commented-out. To recap:
then
in visual studio code (or any text editor) I changed line 3 of package.json: "version": "1.0.0", and then also in a text editor in package.json I added to line 5: "scripts": {
"start": "electron ."
}, and then back to my command line
and it worked the first try. I had to ipconfig /renew just to make this comment. I have no idea why it wouldn't work for you. I am on Powershell 5 and Windows 10 but I doubt thats the issue |
Thanks for the tips about my project setup. I will make the changes and try to duplicate your way of starting everything up. I'll report back soon. |
Just wanted to report that I am having the same problem with relative paths on Windows. I too am using this within an electron project. Absolute paths work fine. Node: Update: |
I have the same problem. https://github.com/dhuber666/Powershell-SAS-Tool What is the correct path to start this script I tried several paths but I always get the error that it couldn't find the ps1 file. |
I see you are using Electron and Webpack. Are you sure your issue is the same as this guy's? (His issue seemed to be setting up a basic project) or was your issue more like #49 where you make your electron build and powershell.exe cannot see the script you packed up in your asar? Does it work in dev mode before you do your build? If this is your issue like I told that guy you will want to copy your powershell scripts over to your production build with a post install script. |
Hi, nope it just works when I give it the direct path like it is in the script right now: But this ofc give me the full path starting at my C: etc. I need the project path. So when I build it and I put it on a network drive (so my colleagues can use it) the ps1 scripts still get loaded. I read through the issue but I don't know why I have to copy the ps1 scripts with a gulp task. But then the path isn't correct anymore. So I need a way that it's using the relative path. I'm not so familiar with node's path and path's in general. I think I just need to find the right path function to get this task done. So it's always something like that:
But then again I don't know what path's the node-powershell accepts. Because if I put the ps1 in the same directory as the js file it gets loaded from and do something like that:
And thank you so much for always trying to help me @BenjaminMichael 👍 |
The paths are relative to the execution point not the Javascript file. You would need to specify the path from the point of execution:
even if the javascript is in that same folder. Note that I cannot tell your point of execution as you have no typical electron startup script in your package.json. Also note that powershell.exe cannot see inside an asar so for a production electron build of your electron app you would need a way to provide the program with the scripts. This is a different issue from executing the script in dev mode where your project files are not compressed into an asar. |
I have this kind of setup because I used a boilerplate from github that includes electron and react with webserver. It's so depressing. I have the finished app working when I run it with The closest I have gotten so far is using this:
This is working fine in the dev environment. But when I build it and run it I get the following error in the app:
But the path should be So I'm so confused right now why it resolves this path in the error message and not the correct one. If it would It would be working. I don't run any scripts from package.json besides the |
Webpack and React needlessly complicate such a project in my opinion. I usually start off with https://github.com/electron/electron-quick-start That said, your problem is universal to electron. The electron build process does more than just copy all your files and folders over. It also compresses it into a structure that windows cannot easily see inside of. For that reason you need a post build script that creates a folder to hold the scripts and copies the scripts from your original source into this new folder. You can see in my example project's package.json I have 2 scripts:
First I: node package-win The second script copies over my powershell with a gulp task. |
Thanks again. |
Closed due to lack of response |
I'm having some issues loading a ps1 file using a relative path on a Windows machine.
When I try to add a ps1 using a direct path, such as this, everything works great:
ps.addCommand("C:/dev/powershell-electron-demo/Get-Drives", [{ ComputerName: computer }]);
But then when I try a relative path, such as this, I get an error about it not being found:
ps.addCommand("./Get-Drives", [{ ComputerName: computer }]);
I'm 100% positive my Get-Drives.ps1 is in my root folder, the same folder with my index.html and renderer.js. Everything works great with a direct path. I've tried every combination of forward slash, back slash, double slash, single periods, double periods, etc. Any ideas?
The text was updated successfully, but these errors were encountered: