c# - 在 .Net Core 上需要在 main.py 脚本之前运行 python 命令
问题描述
这是问题所在。
我需要在 ubuntu WSL 上使用 C# .Net core 运行一些 python 文件。(在 Windows 机器上安装 Ubuntu 并在 Ubuntu 中运行 C# dll,使用里面DotNet file.dll
运行 python 文件)
在实际 main.py 文件运行之前,我需要运行以下命令。
python3 -m pip install --user virtualenv
python3 -m venv env
pip install -r requirements.txt
source env/bin/activate
我在 C# 中使用下面的代码来运行 python
ProcessStartInfo start = new ProcessStartInfo
{
FileName = "main.py",
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
};
using (Process process = Process.Start(start))
{
using (StreamWriter reader = process.StandardInput) {
reader.WriteLine("pip install --upgrade pip");
}
using (StreamReader reader = process.StandardOutput)
{
//result = reader.ReadToEnd();
process.WaitForExit();
Task.Delay(TimeSpan.FromSeconds(90)).Wait();
}
}
但它总是失败。任何建议高度赞赏。
解决方案
推荐阅读
- azure - 从 ARM 模板获取 API 管理的公共 IP 地址
- c# - 使用 Contains 或 IndexOf 方法检查值的状态或索引时如何从文本框中检索值?
- visual-studio-code - 如何使用 Visual Studio Code 在美人鱼的甘特时间轴中添加日期
- r - r - 如何增加 ggplot2 中面板背景的大小
- python - 如何在 Flask Web 应用程序中使用现有的 PostGIS 数据库
- php - 在 PHP 中运行的脚本之间存储变量值的最佳方法?
- reactjs - 如何让 webpack 开发服务器检查客户端是桌面还是移动端并响应不同的 html?
- ipc - 消息队列与 TCP IP 套接字。哪个IPC在linux中更快?
- html - 嵌套在 CSS 网格中
- php - php 图片返回空白