简体   繁体   中英

how to execute command on mac os through C#

I am currently generating PDF from html using headless chrome control through .net core application. For that purpose, i have to run the chrome commands through the .net process. I am able to generate the PDF in windows os by running command on cmd.exe.

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

I am not sure about triggering the terminal commands on mac os through the .net process.Is there any way to run command prompt commands from within a C# application? If so how would I do the above one.

Headless Chrome

cmd is useless and unneeded here. It serves absolutely no purpose apart from making things harder to read or reason about. Well, and to run yet another process for some reason. Set the working directory for the started process and just launch the executable. That's much easier.

Of course, for being able to run the same on OS X you can't hardcode the location of the program, but at least you no longer have to worry about having a shell in between as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM