[英]How to Provide parameters to a process
嗨,我正在尝试创建一个用 c# 编写的 Windows 表单应用程序,它将启动、停止并监视它是否正在运行另一个控制台应用程序。
现在我可以在我的 Windows 应用程序上启动控制台应用程序,但是我如何为其 Console.ReadLine 提供值
这是我的代码:
windows 应用程序:
int ProcessIDDaca = 111111111;
private void btnDacaStart_Click(object sender, EventArgs e)
{
try
{
using (Process myprocess = new Process())
{
myprocess.StartInfo.UseShellExecute = false;
myprocess.StartInfo.FileName = @"C:\Users\nx011116\Documents\MachineMonitor\CopyChimp_Server\bin\Debug\CopyChimpServer.exe";
//myprocess.StartInfo.FileName = @"C:\Program Files\Eltima Software\Virtual Serial Port Driver 9.0\vspdconfig.exe";
myprocess.StartInfo.CreateNoWindow = true;
if (btnDacaStart.Text == "Stop")
{
Process proc = Process.GetProcessById(ProcessIDDaca);
proc.Kill();
btnDacaStart.Text = "Start";
lblDacaID.Text = "";
}
else
{
myprocess.Start();
var s = myprocess.Id;
ProcessIDDaca = myprocess.Id;
lblDacaID.Text = s.ToString();
btnDacaStart.Text = "Stop";
}
}
}
catch (Exception ex)
{
}
}
控制台应用程序:
public static string copychimp_server = "";
public static int port_number = 0;
static void Main(string[] args)
{
Console.Write("Enter copychimp server: ");
//Here i need to provide
copychimp_server = Console.ReadLine();
Console.Write("Enter port number: ");
//Here i need to provide
port_number = Convert.ToInt16(Console.ReadLine());
}
还有为什么没有显示,但我可以看到它正在我的任务管理器上运行? 像编程初学者一样,我非常感谢您的帮助。 先感谢您
我已经解决了我的最新代码:
int ProcessIDDaca = 111111111;
private void btnDacaStart_Click(object sender, EventArgs e)
{
try
{
using (Process myprocess = new Process())
{
myprocess.StartInfo.UseShellExecute = false;
myprocess.StartInfo.FileName = @"C:\Users\nx011116\Documents\MachineMonitor\CopyChimp_Server\bin\Debug\CopyChimpServer.exe";
//myprocess.StartInfo.FileName = @"C:\Program Files\Eltima Software\Virtual Serial Port Driver 9.0\vspdconfig.exe";
myprocess.StartInfo.CreateNoWindow = true;
if (btnDacaStart.Text == "Stop")
{
Process proc = Process.GetProcessById(ProcessIDDaca);
proc.Kill();
btnDacaStart.Text = "Start";
lblDacaID.Text = "";
}
else
{
myprocess.StartInfo.Arguments = "test";
myprocess.Start();
var s = myprocess.Id;
ProcessIDDaca = myprocess.Id;
lblDacaID.Text = s.ToString();
btnDacaStart.Text = "Stop";
}
}
}
catch (Exception ex)
{
}
}
public static string copychimp_server = "";
public static int port_number = 0;
static void Main(string[] args)
{
Console.Write("Enter copychimp server: ");
//Here i need to provide
copychimp_server = args[0];
Console.Write("Enter port number: ");
//Here i need to provide
port_number = Convert.ToInt16(Console.ReadLine());
}
参考链接c#中如何将参数传递给另一个进程
为什么将 myprocess.StartInfo.CreateNoWindow 设置为 true? 将其设置为 false 并重试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.