Running PhantomJs from command prompt using C#

2019-08-10 20:05发布

问题:

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.



标签: c# phantomjs