2013-05-21 48 views
1

我試圖運行PhantomJs.exe拋出C#代碼。 我的代碼:從命令提示符使用C運行PhantomJs#

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(); 

當我運行它會WorkingDirectory E:/而且參數不是寫在命令提示符。

任何好友都可以建議我在cmd.exe上運行參數嗎?

+0

什麼是你的,你嘗試作爲參數字符串。?而不是'這裏的一些字符串代碼' –

+0

如何決定參數不寫? – Tommi

+0

argument =「phantomjs highcharts-convert.js -infile options1.json -outfile chart1.png -scale 2.5 -width 300 -constr Chart -callback callback .js「 –

回答

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";代替