gpt4 book ai didi

c# - 如何从 C# 项目中调用另一个进程?

转载 作者:太空宇宙 更新时间:2023-11-03 13:58:33 24 4
gpt4 key购买 nike

是否可以从主程序调用一些进程(或 exe),向它发送一些参数,完成一些处理并返回结果?如果可能,哪种方法最好?

我有一个用于管理工厂的 wpf 应用程序。此应用程序用于不同的工厂。唯一不同的是磨机使用的称重串口通讯方式不同。目前,称重部分已编程到应用程序中。但这很难维护,因为我必须根据地磅拥有不同版本的项目。所以我想要这样:我有主项目的单一版本。主项目调用另一个进程(或exe)并发送一些参数。该 exe 进行称重并发回权重。 enter image description here

最佳答案

如果你只有另一个 exe 文件,那么你可以使用(取自 http://www.dotnetperls.com/process-start )运行它

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "dcm2jpg.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = "-f j -o \"" + ex1 + "\" -z 1.0 -s y " + ex2;

try
{
// Start the process with the info we specified.
// Call WaitForExit and then the using statement will close.
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
}
catch
{
// Log error.
}

关于c# - 如何从 C# 项目中调用另一个进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11364818/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com