1

My goal is to run two commands one after another to build Electron. I am using Powershell, not bash to achieve this so I can, ultimately, build a win32 binary.

Running via Powershell:

PS C:\Users\digit\Dropbox\Programming\project\app> npm run build:fake --verbose
npm info it worked if it ends with ok
npm verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
npm verb cli   'C:\\Users\\digit\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli   'run',
npm verb cli   'build:fake',
npm verb cli   '--verbose' ]
npm info using [email protected]
npm info using [email protected]
npm verb run-script [ 'prebuild:fake', 'build:fake', 'postbuild:fake' ]
npm info lifecycle [email protected]~prebuild:fake: [email protected]
npm info lifecycle [email protected]~build:fake: [email protected]

> [email protected] build:fake C:\Users\digit\Dropbox\Programming\project\app
> echo 'test'; echo 'test2'

'test'; echo 'test2'

npm verb lifecycle [email protected]~build:fake: unsafe-perm in lifecycle true
npm verb lifecycle [email protected]~build:fake: PATH: C:\Users\digit\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\digit\Dropbox\Programming\project\app\node_modules\.bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\libnvvp;C:\Python27\;C:\Python27\Scripts;C:\Program Files (x86)\Razer Chroma SDK\bin;C:\Program Files\Razer Chroma SDK\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\WINDOWS\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Git\cmd;C:\ProgramData\chocolatey\bin;C:\Program Files\nodejs\;C:\Program Files (x86)\Yarn\bin\;C:\Program Files\doxygen\bin;C:\Program Files\CMake\bin;C:\Program Files\NVIDIA Corporation\Nsight Compute 2019.1\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Users\digit\AppData\Local\Microsoft\WindowsApps;C:\Users\digit\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\digit\AppData\Local\hyper\app-2.1.2\resources\bin;C:\Users\digit\AppData\Roaming\npm;C:\Users\digit\AppData\Local\Yarn\bin;C:\Program Files\NASM;C:\Program Files\nodejs;C:\MinGW\bin;C:\MinGW\msys\1.0;
npm verb lifecycle [email protected]~build:fake: CWD: C:\Users\digit\Dropbox\Programming\project\app
npm info lifecycle [email protected]~postbuild:fake: [email protected]
npm verb exit [ 0, true ]
npm timing npm Completed in 200ms
npm info ok
PS C:\Users\digit\Dropbox\Programming\project\app> wsl npm run build:fake

For some reason it echos the whole command instead when it should run each command delimited by a semi-colon.

Running this on Ubuntu works fine:


> [email protected] build:fake /mnt/c/Users/digit/Dropbox/Programming/project/app
> echo 'test'; echo 'test2'

test
test2

I am utilizing https://www.npmjs.com/package/run-script-os

OS: Windows 10

1 Answer 1

3

npm uses cmd.exe to run scripts on Windows by default - irrespective of what shell you happen to invoke the npm executable from, which explains your symptom.[1]

If you want npm to use PowerShell to run scripts with, use (npm v5.1+):

Windows PowerShell:

npm config set script-shell powershell

PowerShell Core:

npm config set script-shell pwsh

Note: The above configures PowerShell for use with all your projects; you can also do it on a per-project basis - see this answer.


[1] ; is not a stament separator in cmd.exe, and '...'-quoting is not recognized; therefore, the echo command interpreted 'test'; echo 'test2' as a literal string to echo.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.