Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 25th, 2005, 06:26 PM
Registered User
 
Join Date: Oct 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Manipulating Processes ?

Here is a sample of my code.
----------------------------------------

using System;
using System.IO;
using System.Diagnostics;

namespace process
{

class Class1
{
public static string status = null;
public static string sfile = @"C:\kush\Tester\bin\debug\tester.exe";

[STAThread]
static void Main(string[] args)
{
launcher(sfile);
System.Console.WriteLine(status);
System.Console.ReadLine();
}

public static string launcher(string file)
{
Process p = null;

try
{ p = new Process();
p.StartInfo.FileName = file;
p.StartInfo.CreateNoWindow = false;
p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
//p.StartInfo.RedirectStandardOutput = true;
//p.StartInfo.UseShellExecute = false;
p.Start(); //status = p.StandardOutput.ReadToEnd(); p.WaitForExit();
p.Close();
}
catch (Exception ex)
{
Console.WriteLine("Exception Occured : {0}, {1}",ex.Message,ex.StackTrace.ToString());
}
return status;
}
}
}
----------------------------------------------
using System;
using System.IO;
using System.Threading;

namespace tester
{
class Test
{
[STAThread]
static void Main(string[] args)
{
System.Console.WriteLine("Tester");
Thread.Sleep(5000);
}
}
}
-----------------------------------------------
When i run the program as above, it works fine. The parent process (Process.class1) calls the child process (Tester.test). In other words i can see both the parent and child process on the screen.

As soon as i uncomment the code below

p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
status = p.StandardOutput.ReadToEnd

i can no longer see the child process when i run the parent process. Is there a way around in which i could still see the child process in action as well as capture any output given by the child process.

Thanks

 
Old October 26th, 2005, 04:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Copenhagen, , Denmark.
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Why do you want to uncomment those lines, when you want to see the output?

I would suggest that you leave the three lines in the source and then save the status value when finished. This way you both see the output and save it.

Be aware that, if you are going to saave the standard error aswell you might have deadlock problems. I wrote another thread about this a some point.

Jacob.




Similar Threads
Thread Thread Starter Forum Replies Last Post
remote processes gobotsoup ASP.NET 2.0 Basics 1 May 6th, 2007 01:50 PM
Checking Processes AggressiveFish Beginning VB 6 0 September 19th, 2006 01:29 PM
HTML Form to two processes IanC2005 ASP.NET 1.0 and 1.1 Basics 1 April 12th, 2006 05:50 PM
processes in php Moharo Pro PHP 1 November 10th, 2003 08:47 AM
Placing processes in the background ohwail C++ Programming 2 September 10th, 2003 11:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.