473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Running Command line process

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?
Jan 11 '08 #1
4 5937
SendKeys works with VB, otherwise
shell somtehing like "blaerg.exe < input.txt "
and input .txt is like
1
2
3

//CY
Jan 11 '08 #2
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 "
and input .txt is like
1
2
3

//CY
Jan 11 '08 #3
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
Jan 11 '08 #4
The Process needs to start cmd.exe, and the arguments list needs to include
the batfile.

"ga***********@gmail.com" wrote:
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?
Jan 12 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: hplloyd | last post by:
Hi i want my VB.NEt application to run a seperate application from the command line, and then wait until this application has completed before continuing I am currently using ...
10
by: Mandy | last post by:
I have a command line tool that I would like to run from my .NET web application using System.Diagnostics.ProcessStartInfo. I run cmd.exe with this and then pass the command to run the tool as an...
3
by: guy levi | last post by:
Running command line programs from vb.net and capturing the output how do i do this?
9
by: Atley | last post by:
I am looking for a way to run DOS-type commands from within a VB.net 2003 application. I also need to be able to answer questions (ie 'Are You Sure') that the command line may require. ...
2
by: hplloyd | last post by:
Hi I want my VB.NET application to run a command from the command line and then wait for the command to finish before continuing. I am currently using System.Diagnostics.Process.Start(strApp) ...
3
by: Vicky_r | last post by:
hi.. I am using Process class to run a .bat file. The .bat file contains the code to run the Session StateServer. First I have written a command in a text file then I convert it to bat and...
2
by: jetoo | last post by:
Hi there, i'm trying to run a powershell script from a aspx page. Here's the code: //Powershell arguments String powershell = "C:\\WINDOWS\\system32\...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.