使用params在c#中运行linux可执行文件



我需要在c#中运行一个没有运行时参数扩展的linux文件,我想知道你是否可以直接用一些函数来实现这一点,或者你需要在代码中编写一个运行时bash脚本。

示例:

运行c:/app-port=(更改代码中的端口变量(

这是一种典型的方法,可以用参数启动终端应用程序,等待它完成,然后输出它发送到stdout的内容。

using(var p = Process.Start(new ProcessStartInfo
{
FileName = "/bin/ls", // File to execute
Arguments = "~/Documents", // arguments to use
UseShellExecute = false, // use process creation semantics
RedirectStandardOutput = true, // redirect standard output to this Process object
CreateNoWindow = true, // if this is a terminal app, don't show it
WindowStyle = ProcessWindowStyle.Hidden // if this is a terminal app, don't show it
})
{
// Wait for the process to finish executing
p.WaitForExit();
// display what the process output
Console.WriteLine(p.StandardOutput.ReadToEnd());
}

最新更新