【问题标题】:how to execute command on mac os through C#如何通过C#在mac os上执行命令
【发布时间】:2018-04-13 10:26:59
【问题描述】:

我目前正在通过 .net 核心应用程序使用无头镶边控制从 html 生成 PDF。为此,我必须通过 .net 进程运行 chrome 命令。我可以通过在 cmd.exe 上运行命令在 Windows 操作系统中生成 PDF。

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C cd C:\\Program Files (x86)\\Google\\Chrome\\Application\\&chrome --headless --disable-gpu --print-to-pdf http://www.google.com/ ;
process.StartInfo = startInfo;
process.Start();

我不确定通过 .net 进程触发 mac os 上的终端命令。有没有办法从 C# 应用程序中运行命令提示符命令?如果是这样,我该怎么做。

Headless Chrome

【问题讨论】:

    标签: .net terminal command command-prompt google-chrome-headless


    【解决方案1】:

    cmd 在这里是无用且不需要的。除了使事情更难阅读或推理之外,它绝对没有任何目的。好吧,并且出于某种原因运行另一个进程。为启动的进程设置working directory,然后启动可执行文件。这要容易得多。

    当然,为了能够在 OS X 上运行相同的程序,您不能硬编码程序的位置,但至少您不必再担心中间还有一个 shell。

    【讨论】:

      猜你喜欢
      • 2020-05-11
      • 2021-09-09
      • 2012-06-08
      • 2016-08-30
      • 2018-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多