Closed netcore-jroger closed 7 years ago
Can you provide the output of the childProcess.spawnSync('node', ['--version']);
where this does not work?
@vsemozhetbyt
childProcess.spawnSync('node', ['--version']);
not return anything.
I just found that the shell: true
can run properly.
let result = childProcess.spawnSync('node', ['--version'], {
shell: true
});
console.log(result);
work very well. but shell
default value is false. Can I change the default value in global?
@netcore-jroger I suggest you use execSync, which actually spawns a shell to run the command in.
~But spawnSync
returns things for me:~ I'm not on Windows, sorry.
C:\Users\JRoger> node
> require('child_process').spawnSync('node', ['--version'], {shell: true});
@netcore-jroger So if you run require('child_process').spawnSync('node', ['--version']);
in the v6.11.1 RERL, it just exits without any output?
yes !
cc @nodejs/platform-windows
in terminal also without any output.
@vsemozhetbyt
require('child_process').execSync('node', ['--version']);
work very well.
I found a similar question link
In that case it's probably something to do with needing to spawn a batch shell on Windows. If you're running batch commands execSync
is the better choice.
In fact, this is a problem with vscode editing. I have a little bit of debugging vscode code found this problem.
A lot of places in vscode use the child_process.spawn ()
function.
Do you mean node --version
in the cmd.exe
terminal also outputs nothing?
What does where node
output?
is there any way to update the shell in the global default value is true?
I manually modify all vscode editor code using the child_process.spawn () shell is true. The Vscode editor is working properly.
@netcore-jroger, does this work for you, from a command shell:
node -e "console.log(require('child_process').spawnSync('node', ['--version']))"
@bzoz not work. But the following code works fine:
node -e "console.log(require('child_process').spawnSync('node', ['--version'], {shell: true}))"
Is there anything printed out? Any error message?
nothing.
@netcore-jroger that is strange. You should get at least some error message.
Could you try couple more things? What does running where node
returns? Does running require('child_process').spawnSync('node', ['--version'])
from the REPL exits node? I mean, what you get when you do this:
Also, is your D: drive unusual? A subst drive, ram drive, network share, etc>?
Can you also try running require('child_process').spawnSync('not existing')
?
Thanks for your answers!
@bzoz Look at the picture below:
@netcore-jroger In the last case you should escape backslashes: require('child_process').spawnSync('D:\\Program Files\\nodejs\\node.exe');
.
Oh sorry.
The first parameter, if provided with a complete path, has always been normal.
Repeating @bzoz's question:
Also, is your D: drive unusual? A subst drive, ram drive, network share, etc>?
@vsemozhetbyt normal drive.
In good condition.
Does this happen only in REPL? Is there any output if you run a node file.js
with this code in file.js
:
console.log(require('child_process').spawnSync('node', ['--version']));
@vsemozhetbyt
The same result is in the REPL and in the code file.
When I specify the shell
option is true
, it is completely normal
Does this happen with any other .exe
files from path
env in C:
and D:
drives? Is require('child_process').spawnSync('notepad');
OK?
@vsemozhetbyt
invoke notepad
is ok.
Is require('child_process').spawnSync('python', ['-V'])
OK (python
is on the D:
drive, right)?
can also be.
python install path: D:\Program Files\Python27\
Strange.
cc @bnoordhuis, @cjihrig concerning child_process
.
What's strange in this picture is that the REPL seems to exit
And node file.js
also exits without any output or error.
@refack yes. exited.
So I want to say it's something is the system outside of node. @netcore-jroger could you take a look at the event log (run eventvwr.msc
) if it says anything about node.exe
crashing.
I found into the installation directory and execute the command require ('child_process'). SpawnSync ('node', ['--version']);
can work properly.
But it will not work properly on the terminal.
@refack has nothing information in Windows Application events.
@netcore-jroger Can you also post the output of set
or cmd /k set
@refack set
command.
So there are two thing that are not common:
%ProgramFiles% == C:\Program Files
, but nodejs
is in D:\Program Files\nodejs
"
in your %Path%
which is unusual, maybe even the cause...
For example my %Path% is:
d:\code\node-cur$ set Path
Path=D:\bin\dev\VS\Microsoft Visual Studio 2017 Community\VC\Tools\MSVC\14.10.25017\bin\HostX64\x64;D:\bin\dev\VS\Microsoft Visual Studio 2017 Community\Common7\IDE\VC\VCPackages;C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.2;D:\bin\dev\VS\Microsoft Visual Studio 2017 Community\Common7\IDE\CommonExtensions\Microsoft\TestWindow;D:\bin\dev\VS\Microsoft Visual Studio 2017 Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;D:\bin\dev\VS\Microsoft Visual Studio 2017 Community\MSBuild\15.0\bin\Roslyn;D:\bin\dev\VS\Microsoft Visual Studio 2017 Community\Team Tools\Performance Tools;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools\;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\;C:\Program Files (x86)\Microsoft SDKs\F#\4.1\Framework\v4.0\;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64;D:\bin\dev\VS\Microsoft Visual Studio 2017 Community\\MSBuild\15.0\bin;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;D:\bin\dev\VS\Microsoft Visual Studio 2017 Community\Common7\IDE\;D:\bin\dev\VS\Microsoft Visual Studio 2017 Community\Common7\Tools\;C:\Tools\maint\conemu\ConEmu\Scripts;C:\Tools\maint\conemu;C:\Tools\maint\conemu\ConEmu;c:\Program Files\Microsoft MPI\Bin\;C:\Program Files\Docker\Docker\Resources\bin;C:\WINDOWS\system32\Tools;C:\WINDOWS\system32\downlevel;C:\WINDOWS\system32\Java\jre\bin;C:\WINDOWS\system32;C:\WINDOWS\system32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\Wbem;C:\WINDOWS;C:\bin\dev\node;C:\bin\dev\python27;C:\bin\dev\python27\Scripts;C:\bin\git\usr\bin;C:\bin\git\cmd;C:\Tools\maint;C:\Tools\dev;C:\code\tools;C:\code\tools\scripts;.\node_modules\.bin\;C:\Program Files\dotnet\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\
PATHEXT=.JS;.;.CMD;.BAT;.EXE;.MSC;.COM
None of the entries has "
Oh sorry. my set
command run in powershell.
when I run in cmd.exe
output result like this below picture:
In my company's computer:
work very well, can get return value. but
not work and the code behind it will not execute.
I use myself computer:
was work very well.
I have added
D:\Program Files\nodejs\
to the environment variable.This problem caused my vscode editor to not work properly. see#45048199