Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

Running Command line process

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
garykenneally@gmail.com - 11 Jan 2008 14:48 GMT
Hi,

Im trying to run a command line application from C# but i having some
strange problems with it.

Heres the code im using:

System.Diagnostics.Process process = new System.Diagnostics.Process();

                            procPath = @"c:\ae.bat";
                            //string procArgs = " " + fileName + " " + tempFile;
                            System.Diagnostics.ProcessStartInfo info = new
System.Diagnostics.ProcessStartInfo(procPath );

                            //info.Arguments = procArgs;

                            info.UseShellExecute = false;
                            info.RedirectStandardOutput = true;
                            info.RedirectStandardInput = true;
                            info.RedirectStandardError = true;
                            info.CreateNoWindow = false;
                            info.WorkingDirectory = @"c:\";

                            process.StartInfo = info;

                            process.Start();
                            StreamWriter sw = process.StandardInput;
                            StreamReader sr = process.StandardOutput;
                            StreamReader err = process.StandardError;

                            sw.AutoFlush = true;
                            System.Threading.Thread.Sleep(1000);

                            sw.WriteLine("Value1");
                            sw.WriteLine("Value2");
                            sw.Close();
                            //string ret = sr.ReadToEnd();
                            //string error = err.ReadToEnd();

                            if(process != null)
                            {
                                if(process.HasExited == false)
                                    process.WaitForExit(3000);
                                if(process.HasExited == false)
                                    process.Kill();
                            }

If i run this code to start any command line application they all seem
to work fine apart from the one i need.  I need to run the application
with 2 parameters and then pass it more values when it asks for them.
I can see in debug view the test being returned from other
applications but the one im testing with does not return anything to
the debug window.  If i run the bat file manually it works perfectly
and prompts me to enter a value but in C# i dont see any messages
coming from the application.  I have tried using StreamReader on its
standardoutput but it just hangs.

Anyone have any idea why this would be happening?
christery@gmail.com - 11 Jan 2008 15:10 GMT
SendKeys works with VB, otherwise
shell somtehing like "blaerg.exe < input.txt "
and input .txt is like
1
2
3

//CY
garykenneally@gmail.com - 11 Jan 2008 15:33 GMT
The redirection in DOS does not seem to work with this application
either.  Is it possible that some security features were used to stop
this option ?

On Jan 11, 3:10 pm, christ...@gmail.com wrote:
> SendKeys works with VB, otherwise
> shell somtehing like "blaerg.exe < input.txt "
[quoted text clipped - 4 lines]
>
> //CY
christery@gmail.com - 11 Jan 2008 23:02 GMT
On 11 Jan, 16:33, "garykennea...@gmail.com" <garykennea...@gmail.com>
wrote:
> The redirection in DOS does not seem to work with this application
> either.  Is it possible that some security features were used to stop
> this option ?

I dunno, but figure about SendKeys... that simulates keypresses (this
is in VB, havent done that in c#)
redir ony works if stdin is console without any cntrol of cursor/user
(that might "eat it up")

For example if a menu is used and they want to ceep it clean (the
keybord buffer) the program starts with
"eating up" the redirected file. Not what we want now, but the
programmer was not being thinking security,
just did that  to enshure that the program works without problems.

Back to SendKeys in c# then *heh* it there is something like that...

//CY
Family Tree Mike - 12 Jan 2008 00:47 GMT
The Process needs to start cmd.exe, and the arguments list needs to include
the batfile.

> Hi,
>
[quoted text clipped - 54 lines]
>
> Anyone have any idea why this would be happening?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.