使用参数从 .NetCore 运行 bash 命令 [英] run bash command from .NetCore with arguments

查看:39
本文介绍了使用参数从 .NetCore 运行 bash 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从另一个运行一个 .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 [common-options] [[options] path-to-application]

Usage: dotnet [common-options] [[options] path-to-application]

常用选项:--help 显示.NET Core共享框架主机帮助.--版本显示.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 Core 托管应用程序的路径,要执行的 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.

推荐答案

您需要将参数转义为 -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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆