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 npm@6.9.0
npm info using node@v11.11.0
npm verb run-script [ 'prebuild:fake', 'build:fake', 'postbuild:fake' ]
npm info lifecycle app@1.0.0~prebuild:fake: app@1.0.0
npm info lifecycle app@1.0.0~build:fake: app@1.0.0

> app@1.0.0 build:fake C:\Users\digit\Dropbox\Programming\project\app
> echo 'test'; echo 'test2'

'test'; echo 'test2'

npm verb lifecycle app@1.0.0~build:fake: unsafe-perm in lifecycle true
npm verb lifecycle app@1.0.0~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 app@1.0.0~build:fake: CWD: C:\Users\digit\Dropbox\Programming\project\app
npm info lifecycle app@1.0.0~postbuild:fake: app@1.0.0
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:


> app@1.0.0 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

Suhail Doshi
  • 716
  • 1
  • 10
  • 23

1 Answers1

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.

mklement0
  • 382,024
  • 64
  • 607
  • 775