使用C#从命令提示符运行PhantomJs [英] Running PhantomJs from command prompt using C#

查看:421
本文介绍了使用C#从命令提示符运行PhantomJs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行PhantomJs.exe抛出C#代码. 我的代码:

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

运行时它将转到WorkingDirectory E:/,但是参数未在cmd提示符下编写.

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

任何伙伴都可以建议我在cmd.exe上运行参数吗?

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

推荐答案

为了使cmd.exe接受其他命令作为参数,您需要在该命令前加上/K(如果希望cmd窗口保持打开状态)或/C(如果您希望在命令完成后关闭窗口).所以:

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

应该做你所需要的.

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

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆