使用参数从.NetCore运行bash命令 [英] run bash command from .NetCore with arguments
问题描述
我正在尝试从另一个运行一个.NetCore程序。
I am trying to run one .NetCore program from another.
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "sh";
psi.Arguments = "-c dotnet /home/myuser/PublishOutput/myprogram.dll";
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
Process proc = new Process
{
StartInfo = psi
};
proc.Start();
string error = proc.StandardError.ReadToEnd();
if (!string.IsNullOrEmpty(error))
return "error: " + error;
string output = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();
return output;
作为输出,我得到:
Microsoft .NET Core共享框架主机
Microsoft .NET Core Shared Framework Host
版本:1.1.0内部版本:
928f77c4bc3f49d892459992fb6e1d5542cb5e86
Version : 1.1.0 Build : 928f77c4bc3f49d892459992fb6e1d5542cb5e86
用法:dotnet [通用选项] [[选项]到应用程序的路径]
Usage: dotnet [common-options] [[options] path-to-application]
常用选项:--help显示.NET Core
共享框架主机帮助。 --version显示
.NET Core共享框架主机版本。
Common Options: --help Display .NET Core Shared Framework Host help. --version Display .NET Core Shared Framework Host version.
选项:--fx-version要使用的已安装
共享框架的版本。
--additionalprobingpath包含要探测的探测策略和程序集的路径。
Options: --fx-version Version of the installed
Shared Framework to use to run the application.
--additionalprobingpath Path containing probing policy and assemblies to probe for.
应用程序路径:.NET的路径核心托管应用程序,要执行的
dll或exe文件。
Path to Application: The path to a .NET Core managed application, dll or exe file to execute.
如果要调试共享框架主机,请将'COREHOST_TRACE'
设置为'1
If you are debugging the Shared Framework Host, set 'COREHOST_TRACE' to '1' in your environment.
要开始为.NET Core开发应用程序,请从以下位置安装
SDK: http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
To get started on developing applications for .NET Core, install the SDK from: http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
所以我看起来很像运行命令 dotnet ,没有dll路径参数。
So I seems exacly like run command dotnet with no dll path argument.
推荐答案
Y您需要转义 -c
的参数,以便它是一个参数:
You need to escape the argument to -c
so that it is one single argument:
psi.Arguments = "-c \"dotnet /home/myuser/PublishOutput/myprogram.dll\"";
这篇关于使用参数从.NetCore运行bash命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!