1

我正在尝试运行PhantomJs.exethrow C# 代码。我的代码:

Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Normal;
startInfo.FileName = "cmd.exe";
startInfo.WorkingDirectory = @"E:\";
startInfo.Arguments = "some string code here";
startInfo.CreateNoWindow = true;
process.StartInfo = startInfo;
process.Start();

当我运行它时,它会进入 WorkingDirectoryE:/但参数没有写在 cmd 提示符上。

有朋友可以建议我在 cmd.exe 上运行参数吗?

4

1 回答 1

1

为了让 cmd.exe 接受另一个命令作为参数,您需要在该命令之前加上 /K(如果您希望 cmd 窗口保持打开)或 /C(如果您希望窗口在命令之后关闭)已完成)。所以:

argument ="/C phantomjs highcharts-convert.js -infile options1.json -outfile chart1.png -scale 2.5 -width 300 -constr Chart -callback callback.js";

应该做你需要的。

但是,如果您只想运行 PhantomJS 程序,我同意 Tommi 的观点:只需运行该程序,而无需先启动 cmd.exe 进程(即startInfo.FileName = "phantomjs.exe";改用 .

于 2013-05-21T13:05:36.753 回答