Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ubuntu中使用c#编写子进程stdin?_C#_Ubuntu - Fatal编程技术网

如何在ubuntu中使用c#编写子进程stdin?

如何在ubuntu中使用c#编写子进程stdin?,c#,ubuntu,C#,Ubuntu,我绝对不擅长制作软件,尤其是c#,但有一次我需要一些小的。我不得不执行一些终端命令,我面临着sudo问题 proc = new System.Diagnostics.Process (); proc.StartInfo.FileName = "/bin/bash"; proc.StartInfo.Arguments = "-c \" " + "sudo service apache2 restart" + " \""; proc.StartInfo

我绝对不擅长制作软件,尤其是c#,但有一次我需要一些小的。我不得不执行一些终端命令,我面临着
sudo
问题

proc = new System.Diagnostics.Process ();
        proc.StartInfo.FileName = "/bin/bash";
        proc.StartInfo.Arguments = "-c \" " + "sudo service apache2 restart" + " \"";
        proc.StartInfo.UseShellExecute = false; 
        proc.StartInfo.RedirectStandardOutput = true;
        proc.Start ();
正如你所知,在命令sudo之后,我必须输入密码,但我想自动输入。也许我可以在我不知道的时候写。
或者我可以使用sudoidunno限制该命令。请帮助我在windows的ubuntu中安装dotnet core 检查官方文件
在windows的ubuntu中安装dotnet core 检查官方文件

您可以查看以下示例:
它是为Windows编写的,但与您希望获得的行为完全相同。

您可以查看以下示例:
它是为Windows编写的,但它与您希望获得的行为完全相同。

问题到底是什么,因为您似乎不知道自己真正想要什么…?我想执行sudo service apache2 restart命令,但它不起作用。很明显,因为密码是必需的,但我不能键入与c#程序工作时相同的密码。问题到底是什么,因为您似乎不知道自己真正想要什么…?我想执行命令sudo service apache2 restart,但它不起作用。显然,因为密码是必需的,但我不能键入与c#程序工作相同的密码。