【问题标题】:Running PhantomJs from command prompt using C#使用 C# 从命令提示符运行 PhantomJs
【发布时间】:2013-05-24 18:08:23
【问题描述】:

我正在尝试运行PhantomJs.exe throw 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();

当我运行它时,它会转到 WorkingDirectory E:/,但参数没有写在 cmd 提示符上。

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

【问题讨论】:

  • 你尝试过的字符串是什么?而不是some string code here
  • 你如何确定 args 不写?
  • argument ="phantomjs highcharts-convert.js -infile options1.json -outfile chart1.png -scale 2.5 -width 300 -constr Chart -callback callback.js"
  • Tommi:代码运行压力很大,没有任何错误,但我传递的参数不是在命令提示符上写入/显示
  • 所以进程会运行一段代码 cmd phantomjs highcharts-convert.js -infile options1.json -outfile chart1.png -scale 2.5 -width 300 -constr Chart -callback callback.js 为什么不启动phantomjs直接?

标签: c# phantomjs


【解决方案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";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-01
    • 1970-01-01
    • 2017-10-01
    • 1970-01-01
    • 2013-05-10
    • 1970-01-01
    • 2010-11-30
    相关资源
    最近更新 更多