无法通过 wmic 启动 npm
Can't start npm via wmic
如果我放入 bat 文件命令来启动 node
wmic process call create "npm run go","%~dp0."
一切正常:
D:\Temp\Supertemp\wmic npm>wmic process call create "node go","D:\Temp\Supertemp\wmic npm\."
Идет выполнение (Win32_Process)->Create()
Метод успешно вызван.
Параметры вывода:
instance of __PARAMETERS
{
ProcessId = 13292;
ReturnValue = 0;
};
但是如果我改用npm
wmic process call create "npm run go","%~dp0."
出现错误9,according to msdn msdn表示找不到路径:
D:\Temp\Supertemp\wmic npm>wmic process call create "npm run go","D:\Temp\Supertemp\wmic npm\."
Идет выполнение (Win32_Process)->Create()
Метод успешно вызван.
Параметры вывода:
instance of __PARAMETERS
{
ReturnValue = 9;
};
文件package.json
:
{
"name": "wmic-npm-test",
"version": "0.0.0",
"scripts": {
"go": "node go"
}
}
文件go.js
:
setInterval(function () {
console.log(require('process').cwd());
}, 1000);
如果只是从控制台启动 npm
,一切正常:
D:\Temp\Supertemp\wmic npm>npm run go
> wmic-npm-test@0.0.0 go D:\Temp\Supertemp\wmic npm
> node go
D:\Temp\Supertemp\wmic npm
D:\Temp\Supertemp\wmic npm
我通过 wmic
to get process id.
启动它
像这样尝试(我在问题下的评论中的模式详细信息):
@echo off
for %%a in (npm.cmd) do set "npm_path=%%~f$PATH:a"
echo %npm_path%
wmic process call create "cmd.exe /c call \"%npm_path%\" ","%~dp0."
npm.cmd
和 npm
文件 sh
:
D:\Temp\Supertemp\wmic npm>where npm
C:\Program Files\nodejs\npm
C:\Program Files\nodejs\npm.cmd
要执行 npm
命令,您需要指定要 运行 cmd-file:
wmic process call create "npm.cmd run go","%~dp0."
如果我放入 bat 文件命令来启动 node
wmic process call create "npm run go","%~dp0."
一切正常:
D:\Temp\Supertemp\wmic npm>wmic process call create "node go","D:\Temp\Supertemp\wmic npm\."
Идет выполнение (Win32_Process)->Create()
Метод успешно вызван.
Параметры вывода:
instance of __PARAMETERS
{
ProcessId = 13292;
ReturnValue = 0;
};
但是如果我改用npm
wmic process call create "npm run go","%~dp0."
出现错误9,according to msdn msdn表示找不到路径:
D:\Temp\Supertemp\wmic npm>wmic process call create "npm run go","D:\Temp\Supertemp\wmic npm\."
Идет выполнение (Win32_Process)->Create()
Метод успешно вызван.
Параметры вывода:
instance of __PARAMETERS
{
ReturnValue = 9;
};
文件package.json
:
{
"name": "wmic-npm-test",
"version": "0.0.0",
"scripts": {
"go": "node go"
}
}
文件go.js
:
setInterval(function () {
console.log(require('process').cwd());
}, 1000);
如果只是从控制台启动 npm
,一切正常:
D:\Temp\Supertemp\wmic npm>npm run go
> wmic-npm-test@0.0.0 go D:\Temp\Supertemp\wmic npm
> node go
D:\Temp\Supertemp\wmic npm
D:\Temp\Supertemp\wmic npm
我通过 wmic
to get process id.
像这样尝试(我在问题下的评论中的模式详细信息):
@echo off
for %%a in (npm.cmd) do set "npm_path=%%~f$PATH:a"
echo %npm_path%
wmic process call create "cmd.exe /c call \"%npm_path%\" ","%~dp0."
npm.cmd
和 npm
文件 sh
:
D:\Temp\Supertemp\wmic npm>where npm
C:\Program Files\nodejs\npm
C:\Program Files\nodejs\npm.cmd
要执行 npm
命令,您需要指定要 运行 cmd-file:
wmic process call create "npm.cmd run go","%~dp0."