gpt4 book ai didi

windows - 无法通过 wmic 启动 npm

转载 作者:可可西里 更新时间:2023-11-01 11:45:35 25 4
gpt4 key购买 nike

如果我放入 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 .

附言:Same question in Russian.

最佳答案

像这样尝试(我在问题下的评论中的模式详细信息):

@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."

关于windows - 无法通过 wmic 启动 npm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46194909/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com