Running PhantomJs from command prompt using C#

戏子无情 提交于 2019-12-24 17:43:08

问题


I am trying to run PhantomJs.exe throw C# code. My Code :

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

When I run it is going to WorkingDirectory E:/ but Arguments are not writing on cmd prompt.

Can any buddy suggest me to run arguments on cmd.exe?


回答1:


In order to get cmd.exe to accept a further command as an argument, you need to precede that command with /K (if you want the cmd window to stay open) or /C (if you want the window to close after the command has completed). So:

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

should do what you need.

However, if you just want to run the PhantomJS program, I agree with Tommi: just run that without starting a cmd.exe process first (i.e. use startInfo.FileName = "phantomjs.exe"; instead.



来源:https://stackoverflow.com/questions/16667737/running-phantomjs-from-command-prompt-using-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!