Computer Hope
Software => Computer programming => Topic started by: gixmoguy on January 07, 2017, 01:25:48 PM
-
So im trying to create a program pretty much that will open other programs upon exit or with a time delay. I get no build errors but everytime i run my program i get the error Cannot start process because a file name has not been provided. but launches the first program anyways just not the other one upon exit. anyone see any issues with the code i provided. Thanks alot appreciate any help :)
using System;
using System.Diagnostics;
using System.Diagnostics.Contracts;
namespace ProcessExitSample
{
class testsandboxprogram
{
static void Main(string[] args)
{
Contract.Requires(args != null);
try
{
//why in the literal *censored* am i getting an error for no name!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!WHEN I DEFINED THE PATH
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;
}
}
}
}
-
Process.Start() isn't going to give the firstProc instance any information about the file you specified as a parameter, as it creates a new Process and starts it and returns that Process as the return value.
You probably want something like this:
ProcessStartInfo FirstProcInfo = new ProcessStartInfo(@"C:\Path\To\executable.exe");
var FirstProc = Process.Start(FirstProcInfo);
FirstProc.WaitForExit();
ProcessStartInfo SecondProcInfo = new ProcessStartInfo(@"C:\Path\To\second\executable.exe");
var SecondProc = Process.Start(SecondProcInfo);
-
Process.Start() isn't going to give the firstProc instance any information about the file you specified as a parameter, as it creates a new Process and starts it and returns that Process as the return value.
You probably want something like this:
ProcessStartInfo FirstProcInfo = new ProcessStartInfo(@"C:\Path\To\executable.exe");
var FirstProc = Process.Start(FirstProcInfo);
FirstProc.WaitForExit();
ProcessStartInfo SecondProcInfo = new ProcessStartInfo(@"C:\Path\To\second\executable.exe");
var SecondProc = Process.Start(SecondProcInfo);
thanks alot for the help im now using
ProcessStartInfo FirstProcInfo = new ProcessStartInfo(@"C:\Program Files (x86)\Steam\steamapps\common\BattleBlock Theater\BattleBlockTheater.exe");
var FirstProc = Process.Start(FirstProcInfo);
firstProc.WaitForExit();
ProcessStartInfo SecondProcInfo = new ProcessStartInfo(@"C:\Program Files (x86)\Steam\steamapps\common\BattleBlock Theater\BattleBlockTheater.exe");
var SecondProc = Process.Start(SecondProcInfo);
}
catch (Exception ex)
{
Console.WriteLine("Something went wrong :) " + ex.Message);
return;
}
}
}
}
Not sure if it matters or not but im trying to open the same exe after it exits from the first one so opens up exe if you exit that exe it opens the same one up again. Not sure if that matters but im getting the method or operation is not implemented the first exe opens up correctly. the second one doesnt open up apon closing it tho
-
That code wouldn't even compile. You defined the v ariable as FirstProc but then used it as firstProc.
anyway, Steam changes everything. When you launch a steam-managed game by itself it will launch steam telling it to launch itself and exit, so WaitForExit() will return immediately.
I don't get "method or Operation is Not Implemented".
-
That code wouldn't even compile. You defined the v ariable as FirstProc but then used it as firstProc.
anyway, Steam changes everything. When you launch a steam-managed game by itself it will launch steam telling it to launch itself and exit, so WaitForExit() will return immediately.
I don't get "method or Operation is Not Implemented".
changed up my code a bit now compiles without any errors
using System;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Threading.Tasks;
namespace ProcessExitSample
{
class testsandboxprogram
{
static void Main(string[] args)
{
try
{
//why in the literal *censored*
ProcessStartInfo FirstProcInfo = new ProcessStartInfo(@"C:\Program Files (x86)\Steam\steamapps\common\BattleBlock Theater\BattleBlockTheater.exe");
var FirstProc = Process.Start(FirstProcInfo);
Console.WriteLine("First process Started: ");
System.Threading.Thread.Sleep(4000);
Task.Delay(2000);
// should run the second program here
ProcessStartInfo SecondProcInfo = new ProcessStartInfo(@"C:\Program Files (x86)\Steam\steamapps\common\BattleBlock Theater\BattleBlockTheater.exe");
var SecondProc = Process.Start(SecondProcInfo);
}
catch (Exception ex)
{
Console.WriteLine("Something went wrong :) " + ex.Message);
return;
}
}
}
}
the only thing now is session 1 terminates once session 2 launches decided ill just work with launching two at the same time.