Javascript 如何在TS中运行命令?

Javascript 如何在TS中运行命令?,javascript,node.js,typescript,Javascript,Node.js,Typescript,我试图从TS运行命令 function executeCommand(command : string, callback: (error: ExecException, stdout : string, stderr : string) => void): void { const path= path.join(vscode.workspace.rootPath,"products"); exec(command, {cwd: '${path}'}, callbac

我试图从TS运行命令

function executeCommand(command : string, callback: (error: ExecException, stdout : string, stderr : string) => void): void  {
    const path= path.join(vscode.workspace.rootPath,"products");

    exec(command, {cwd: '${path}'}, callback);
}

       const command = ({
            'darwin': ``,
            'linux': `cf env`,
            'win32': `cf env`
        } as any)[platform];


 executeCommand(command, (error, stdout, stderr) => {
            if (error) {
                console.warn(error);
            }
      ...
 }
我想在不同的路径上运行命令
cf env
,因此我尝试更改cwd

当我这样做时,我犯了一个错误:

生成C:\WINDOWS\system32\cmd


当我删除cwd时,它工作了,但我需要使用“cwd”选项,您所做的是尝试将路径设置为文本字符串:
${path}

要使用字符串插值,必须使用反勾号而不是单引号,如下所示:

`${path}`//解析为路径
但是,由于没有对任何内容使用插值,因此可以直接将路径放入函数中:

exec(命令,{cwd:path},回调);
获取的错误是因为路径
${path}
无效,cmd未启动