![](/img/trans.png)
[英]How can I pass multiple cell values of datagridview from one form to another at same time in C#?
[英]How can i pass values from a C# form into Python
我在后台使用Visual C#作为UI和Python。
这可能吗?
您可以在后台的新进程中启动python,然后将表单项作为参数传递给进程启动信息,就好像您是从命令行运行python脚本一样,如下所示:
var start = new ProcessStartInfo
{
FileName = _pathToPythonExecutable,
Arguments = string.Format(" {0} --arg1 {1}",_pathToYourPythonScript, //formItemValue),
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardInput = true,
RedirectStandardError = true,
WorkingDirectory = _currentWorkingDirectory
};
using (Process process = Process.Start(start))
{
// Do stuff
}
您会在开始信息中看到,我已经告诉过程重定向StandardInput,Standard Output和Standard Error。 这是在进程之间传递数据的另一种方法。
您将这样写到标准输入:
process.StandardInput.Write(input);
process.StandardInput.Close();
标准输出和标准错误是流,因此您可以像这样读取它们
// This would be the same for standard error
using (StreamReader reader = process.StandardOutput)
{
result = reader.ReadToEnd();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.