c# - 使用 .NET Core 在 Linux 中通过“/bin/bash”执行 .sh(bash 脚本)文件
问题描述
操作系统:Linux 4.15.0-48-generic #51-Ubuntu
框架:.NET Core 4.6.27817.03
我在下面有以下sample.sh
文件:
#!/bin/bash
netstat --tcp --listen --numeric-ports -p
以及执行此文件的以下函数:
string filePathExecute = "./Assets/SystemTests/sample.sh";
FileInfo fileInfo = new FileInfo(filePathExecute);
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = true;
startInfo.FileName = "/bin/bash";
startInfo.Arguments = $"\"{fileInfo.FullName}\"";
Process process = Process.Start(startInfo);
但我得到以下输出:
xdg-open: unexpected argument '/home/{filePathHere}/Assets/SystemTests/sample.sh'
Try 'xdg-open --help' for more information.
如何让我的应用程序打开一个新的终端窗口并sample.sh
在其中运行?
解决方案
经过 10 分钟的试验,一个经典的发现解决方案发生了。不知道为什么,但在跟随标志之后,它开始工作:
startInfo.UseShellExecute = false;
在运行 powershell.ps1 文件时,我不会在 Windows 上执行此操作。此外,此方法还没有打开新窗口,在相同的窗口上运行,但现在它可以工作了。
推荐阅读
- outlook-2019 - Outlook 2016 2019 随机丢失已发送项目
- python - 实现自定义梯度下降函数的问题
- python-3.x - 如何训练从 kaggle 下载的图像的 AMD 测试数据集
- django - 带有正则表达式验证器的 Django 模型字段不起作用
- android - 如何在我已经打开离子和电容器代码的同一个 Android Studio 中导入/打开 Twilio android 代码?
- mysql - 我想减少 MYSQL 查询执行时间。我的查询需要很长时间?
- android - Android Studio 更改页面引导位置
- jmeter - jemeter 中每秒的请求不超过每秒 4 个
- c++ - 是否可以获得字符串的某个字符?
- node.js - “消息”中的未知名称“time_to_live”: