EDN Admin
Well-known member
Trying to see if we can use C# to drive unit test environment and hitting a showstopper: Process.ExitCode of invoked Process seems to be getting lost(getting 0 instead of expected 1).
Here is sample program:
<pre class="prettyprint" style=" using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace a
{
class Program
{
static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine(System.AppDomain.CurrentDomain.FriendlyName + " <depth> [<multiply>]");
Environment.Exit(-1);
}
int n = int.Parse(args[0]);
ProcessStartInfo psi = new ProcessStartInfo();
psi.CreateNoWindow = false;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.UseShellExecute = false;
if (n == 0)
{
Environment.Exit(1);
}
else
{
psi.FileName = System.AppDomain.CurrentDomain.FriendlyName;
psi.Arguments = (n - 1).ToString();
}
List<Process> pss = new List<Process>();
int multiply =
(args.Length > 1) ? int.Parse(args[1]) : 1;
for (int i = 0; i < multiply; i++)
{
pss.Add(Process.Start(psi));
}
foreach (Process p in pss)
{
p.WaitForExit();
if (p.ExitCode != 1)
{
Console.WriteLine("Got unexpected rc: " + p.ExitCode);
}
Console.Write(.);
p.Close();
p.Dispose();
}
Environment.ExitCode = 1;
}
}
}[/code]
<br/>
And here is sample output:
<pre class="prettyprint" style=" C:testeca>abinDebuga.exe 100 20
........................................................................................................................................................................................................
........................................................................................................................................................................................................
.............................................................................................................................................Got unexpected rc: 0
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
...........................................................
C:testeca>[/code]
<br/>
There should be no "Got unexpected rc: 0" message, obviously.
Why is this happening? Any ideas on how to troubleshoot this further? This is on Win7/64.
Thanks!
By the way, I have raised http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/9e7374dc-1e21-4ee7-a2dd-6f34a6279c61
similar question but about VC++ in VC++ forum.<br/>
<
--A
<br/>
View the full article
Here is sample program:
<pre class="prettyprint" style=" using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace a
{
class Program
{
static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine(System.AppDomain.CurrentDomain.FriendlyName + " <depth> [<multiply>]");
Environment.Exit(-1);
}
int n = int.Parse(args[0]);
ProcessStartInfo psi = new ProcessStartInfo();
psi.CreateNoWindow = false;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.UseShellExecute = false;
if (n == 0)
{
Environment.Exit(1);
}
else
{
psi.FileName = System.AppDomain.CurrentDomain.FriendlyName;
psi.Arguments = (n - 1).ToString();
}
List<Process> pss = new List<Process>();
int multiply =
(args.Length > 1) ? int.Parse(args[1]) : 1;
for (int i = 0; i < multiply; i++)
{
pss.Add(Process.Start(psi));
}
foreach (Process p in pss)
{
p.WaitForExit();
if (p.ExitCode != 1)
{
Console.WriteLine("Got unexpected rc: " + p.ExitCode);
}
Console.Write(.);
p.Close();
p.Dispose();
}
Environment.ExitCode = 1;
}
}
}[/code]
<br/>
And here is sample output:
<pre class="prettyprint" style=" C:testeca>abinDebuga.exe 100 20
........................................................................................................................................................................................................
........................................................................................................................................................................................................
.............................................................................................................................................Got unexpected rc: 0
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
........................................................................................................................................................................................................
...........................................................
C:testeca>[/code]
<br/>
There should be no "Got unexpected rc: 0" message, obviously.
Why is this happening? Any ideas on how to troubleshoot this further? This is on Win7/64.
Thanks!
By the way, I have raised http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/9e7374dc-1e21-4ee7-a2dd-6f34a6279c61
similar question but about VC++ in VC++ forum.<br/>
<
--A
<br/>
View the full article