我的c#代码工作正常,在UI自动化期间在特定服务器框中运行作业。我需要节点js中的等效代码。
ProcessStartInfo startinfo = new ProcessStartInfo();
startinfo.FileName = string.Format("schtasks.exe");
string command = string.Format(" /run /s {0} /tn \"{1}\"", "serverbox", "Jobname");
startinfo.Arguments = command;
startinfo.CreateNoWindow = true;//Not much important
startinfo.UseShellExecute = false;//Not much important
startinfo.WindowStyle = ProcessWindowStyle.Hidden;//Not much important
Common.Log.Info("Executing Command - " + command);
Process proc = new Process();
proc = Process.Start(startinfo);
我在node.js中有以下代码,它会抛出" args选项的值不正确"错误。
function executeProcess() {
var command = new String(" /run /s {0} /tn \"{1}\"", "serverbox", "jobname");
exec(command, function (err, stdout, stderr) {
console.log("Running job");
callback(err, stdout, stderr, data)
});
};
答案 0 :(得分:1)
String构造函数只接受单个参数。 你的错误在这里:
var command = new String(" /run /s {0} /tn \"{1}\"", "serverbox", "jobname");
为避免错误,请使用名为string templates
的JavaScript功能:
const command = ` /run /s "${serverbox}" /tn "${jobname}"`