I am starting TCC/LE 13.06.77 x64 on Windows 7 using C# and the RunExternalExe() method from [1] to run a .btm file from my C# program. While I was developing and testing I was running with the Visual Studio 2012 debugger and everything worked fine. However, when I try running outside the debugger the TCC/LE process never returns? Once I forcefully terminate my program I can see my .btm file did everything I wanted it to do.
I tried a no-op.btm that looks like this:
and the same thing happens.
The Process.StandardOutput Property documentation [2] discusses a possible deadlock issue but the RunExternalExe() method seems to use the suggested technique to avoid it.
I even just tried starting the process and not bothering to capture the script output. The interesting thing is that then my C# program's window suddenly hides itself when I start my TCC/LE process and I have to use the Task Manager to kill it. If I remove the /H startup option, then my window no longer disappears and the process doesn't hang. So it seems that TCC/LE started as a child process thinks my C# window is its window? Looks like a bug to me?
In order to capture the script output, I had to change RunExternalExe() from:
It doesn't matter if the /H startup option is specified or not in this case.
The ProcessStartInfo Class documentation [3] says CreateNoWindow:
Things then work, but every time I need to run my .btm file (and it can be many times) a console window opens and then quickly closes.
So my questions are:
When I was developing I of course had a TCC/LE window open with the Help file displayed. But during further "live" testing, I soon found that I was getting Unknow Command errors for a TCC alias I was using. Seems obvious now, but aliases by default are "global" so my C# launched TCC/LE process was getting its aliases from my open TCC/LE window. My startup command now looks like:
where I explicitly say where my TCStartup file (with my aliases) is located. I also use /L: to turn off all global lists for aliases, history, etc. This ensures that my program works the same whether or not a TCC/LE window is open. I added the /S switch in hopes it would solve the process hanging issue but it seems to make no difference.
[1] http://stackoverflow.com/questions/206323/how-to-execute-command-line-in-c-get-std-out-results
[2] http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx
[3] http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx
I tried a no-op.btm that looks like this:
@echo off
echo %1 %2
exit
echo %1 %2
exit
and the same thing happens.
The Process.StandardOutput Property documentation [2] discusses a possible deadlock issue but the RunExternalExe() method seems to use the suggested technique to avoid it.
I even just tried starting the process and not bothering to capture the script output. The interesting thing is that then my C# program's window suddenly hides itself when I start my TCC/LE process and I have to use the Task Manager to kill it. If I remove the /H startup option, then my window no longer disappears and the process doesn't hang. So it seems that TCC/LE started as a child process thinks my C# window is its window? Looks like a bug to me?
In order to capture the script output, I had to change RunExternalExe() from:
process.StartInfo.CreateNoWindow = true;
to:process.StartInfo.CreateNoWindow = false;
It doesn't matter if the /H startup option is specified or not in this case.
The ProcessStartInfo Class documentation [3] says CreateNoWindow:
"Gets or sets a value indicating whether to start the process in a
new window."
new window."
Things then work, but every time I need to run my .btm file (and it can be many times) a console window opens and then quickly closes.
So my questions are:
- Why does my program work with the Visual Studio 2012 debugger, but not outside of it?
- Why does the TCC/LE /H startup option hide my C# program window?
- Why does starting the process in a new window fix things?
- Is there some way to run a TCC/LE .btm file from C# without having a console window flash open and then close?
/H /C c:\myTCCStartupDir\mybatchfile.btm
When I was developing I of course had a TCC/LE window open with the Help file displayed. But during further "live" testing, I soon found that I was getting Unknow Command errors for a TCC alias I was using. Seems obvious now, but aliases by default are "global" so my C# launched TCC/LE process was getting its aliases from my open TCC/LE window. My startup command now looks like:
//TCStartPath=c:\myTCCStartupDir /H /L: /S /C c:\myTCCStartupDir\mybatchfile.btm
where I explicitly say where my TCStartup file (with my aliases) is located. I also use /L: to turn off all global lists for aliases, history, etc. This ensures that my program works the same whether or not a TCC/LE window is open. I added the /S switch in hopes it would solve the process hanging issue but it seems to make no difference.
[1] http://stackoverflow.com/questions/206323/how-to-execute-command-line-in-c-get-std-out-results
I changed:
process.OutputDataReceived += (sender, args) => stdOutput.Append(args.Data);
to:
process.OutputDataReceived +=
(sender, args) => stdOutput.Append(args.Data + Environment.NewLine);
since I noticed that all the output lines were getting jammed together otherwise.
I also added process.Dispose() to avoid memory leaking.
process.OutputDataReceived += (sender, args) => stdOutput.Append(args.Data);
to:
process.OutputDataReceived +=
(sender, args) => stdOutput.Append(args.Data + Environment.NewLine);
since I noticed that all the output lines were getting jammed together otherwise.
I also added process.Dispose() to avoid memory leaking.
[2] http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx
[3] http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx