I have a button in winforms that needed to run batch file and open an exe (monitor.exe
) file when clicked. The batch file snippet:-
@echo on
rem @echo $Id: runnit_navigator.bat,v X.X XXXX/XX/XX XX:XX:XX sxxxaxx Exp $
echo Running runnit_monitor.bat >%TEMP%\runnit_monitor.log
if exist "%CD%\Config.bat" (
call Config.bat >>%TEMP%\runnit_monitor.log
)
if "%1%" NEQ "" (
set SPACE_SITE=%1%
)
@set monitor_start=Y
rem if not defined SPACE_CONFIG (
rem set SPACE_CONFIG=%TEMP%
rem )
if not exist "%PROGRAMDATA%\space\config\%SPACE_SITE% \monitor.properties" (
set SPACE_SITE=NA
)
if "%SPACE_SITE%" EQU "NA" (
call "%SPACE_HOME%\Runnit\runnit_site_monitor.bat" >>%TEMP%\runnit_monitor.log
exit
)
set SPACE_SETTINGS=%PROGRAMDATA%\space\config\%SPACE_SITE%
@set JAVA_EXE=%LoginDialogJavaHome%\bin\monitor.exe
I have tried this code, no error but the exe file is not open at all.
Process proc = new Process();
private void btn1_Click(object sender, EventArgs e)
{
try
{
string batDir = string.Format(@"C:\Program Files\Space\Runnit\");
proc.StartInfo.WorkingDirectory = batDir;
proc.StartInfo.FileName = "runnit_monitor.bat";
proc.StartInfo.CreateNoWindow = false;
proc.Start();
proc.WaitForExit();
proc.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace.ToString());
}
}
Also, this is the output for the above code. After this window pop out, there's nothing happened. But as I put a breakpoint, I can see that some Process
properties return an exception.
Is the way I called process is wrong? Or any suggestion of what can I understand/do to make monitor.exe
run after batch file is read?