我真的不知道为什么这段代码不起作用。每次我收到错误无法启动进程因为没有提供文件名。即使我提供了EXE所在的路径并对其进行了验证。
using System;
using System.Diagnostics;
using System.Diagnostics.Contracts;
namespace ProcessExitSample
{
class testsandboxprogram
{
static void Main(string[] args)
{
Contract.Requires(args != null);
try
{
var firstProc = new Process();
Process.Start(@"PATH TO EXE I WANT TO LAUNCH");
firstProc.EnableRaisingEvents = true;
firstProc.Start();
firstProc.WaitForExit();
//so upon exit should run the second program here
Console.WriteLine("First process exited: " + firstProc.ExitCode);
var secondProc = new Process();
Process.Start(@"PATH TO PROGRAM I WANT TO LAUNCH");
secondProc.Start();
}
catch (Exception ex)
{
Console.WriteLine("Something went wrong sorry :(: " + ex.Message);
return;
}
}
}
}
答案 0 :(得分:0)
StatisticItemDto
您不提供流程启动的路径。我注释掉了不相关的代码,因为它与 var firstProc = new Process();
// Process.Start(@"PATH TO EXE I WANT TO LAUNCH");
firstProc.EnableRaisingEvents = true;
firstProc.Start();
变量无关。
你可能想要:
firstProc
答案 1 :(得分:0)
String myexepath = @"C:\Program Files (x86)\Steam\steamapps\common\BattleBlock Theater\BattleBlockTheater.exe"
当此路径包含时,空格将其括在双引号之间:
Process.Start("\""+myexepath+"\"");
答案 2 :(得分:0)
最明显的是尝试在命令行环境中运行PATH TO EXE I WANT TO LAUNCH
,看看是否出现自我解释的错误。
如果您的路径包含空格,您将看到您正在尝试执行一些空格问题,然后您可以使用Graffito给出的答案。