473,698 Members | 2,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Diagnost ics.Process process = new System.Diagnost ics.Process();

procPath = @"c:\ae.bat" ;
//string procArgs = " " + fileName + " " + tempFile;
System.Diagnost ics.ProcessStar tInfo info = new
System.Diagnost ics.ProcessStar tInfo(procPath );

//info.Arguments = procArgs;

info.UseShellEx ecute = false;
info.RedirectSt andardOutput = true;
info.RedirectSt andardInput = true;
info.RedirectSt andardError = true;
info.CreateNoWi ndow = false;
info.WorkingDir ectory = @"c:\";

process.StartIn fo = info;

process.Start() ;
StreamWriter sw = process.Standar dInput;
StreamReader sr = process.Standar dOutput;
StreamReader err = process.Standar dError;

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

sw.WriteLine("V alue1");
sw.WriteLine("V alue2");
sw.Close();
//string ret = sr.ReadToEnd();
//string error = err.ReadToEnd() ;
if(process != null)
{
if(process.HasE xited == false)
process.WaitFor Exit(3000);
if(process.HasE xited == 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 5950
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.Diagnost ics.Process process = new System.Diagnost ics.Process();

procPath = @"c:\ae.bat" ;
//string procArgs = " " + fileName + " " + tempFile;
System.Diagnost ics.ProcessStar tInfo info = new
System.Diagnost ics.ProcessStar tInfo(procPath );

//info.Arguments = procArgs;

info.UseShellEx ecute = false;
info.RedirectSt andardOutput = true;
info.RedirectSt andardInput = true;
info.RedirectSt andardError = true;
info.CreateNoWi ndow = false;
info.WorkingDir ectory = @"c:\";

process.StartIn fo = info;

process.Start() ;
StreamWriter sw = process.Standar dInput;
StreamReader sr = process.Standar dOutput;
StreamReader err = process.Standar dError;

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

sw.WriteLine("V alue1");
sw.WriteLine("V alue2");
sw.Close();
//string ret = sr.ReadToEnd();
//string error = err.ReadToEnd() ;
if(process != null)
{
if(process.HasE xited == false)
process.WaitFor Exit(3000);
if(process.HasE xited == 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
2111
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 System.Diagnostics.Process.Start(strApp) where strApp is the command line but this simply starts a new process... I want the command to be run as part of the existing process... Any ideas?
10
3817
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 argument to the process. When I try this from a Windows application it works fine, however, when I do this from my web application I get errors. Both applications are running under the same users so am not sure if it is a permissions problem. ...
3
1580
by: guy levi | last post by:
Running command line programs from vb.net and capturing the output how do i do this?
9
4234
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. Thanks, Atley
2
4069
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) where strApp is the the command line text. However this method starts a new process and therefore my application continues without waiting.
3
1758
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 with the help of Process I run the bat file. Now when I use this line "cd C:\WINNT\Microsoft.NET\Framework\v2.0.50727 net start aspnet_state" its
2
3160
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\ \windowspowershell\\v1.0\\powershell.exe";
0
8611
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8876
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7741
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.