473,405 Members | 2,421 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,405 software developers and data experts.

Shell commands in ASP.NET?

Hi,

I want to execute a shell command and retrieve the output of it, is there a
method to do it? All i have found is how to start a process (cmd /C), but i
cannot retrieve the result of the command execution.

For example, it would be ideal if there would be a method like:

string result = ExecuteShellCommand("dir *.txt");

thnx in advance...

Nov 17 '05 #1
3 10140
You want to look at the System.Diagnostics.Process namespace.
Cheers!
Dave
www.aspNetEmail.com

"Allan Rojas" <nd****@thecqgl.com> wrote in message
news:en**************@tk2msftngp13.phx.gbl...
Hi,

I want to execute a shell command and retrieve the output of it, is there a method to do it? All i have found is how to start a process (cmd /C), but i cannot retrieve the result of the command execution.

For example, it would be ideal if there would be a method like:

string result = ExecuteShellCommand("dir *.txt");

thnx in advance...

Nov 17 '05 #2
I already did; but when executing the following code, i get a
System.InvalidOperationException: StandardOut has not been redirected.
System.Diagnostics.Process myP = System.Diagnostics.Process.Start("cmd",
@"/C dir C:\");
Response.Output.Write(myP.StandardOutput.ReadToEnd ());

Thnx in advance...
"dave wanta" <no****@nospam.com> wrote in message
news:O3*************@TK2MSFTNGP10.phx.gbl...
You want to look at the System.Diagnostics.Process namespace.
Cheers!
Dave
www.aspNetEmail.com

"Allan Rojas" <nd****@thecqgl.com> wrote in message
news:en**************@tk2msftngp13.phx.gbl...
Hi,

I want to execute a shell command and retrieve the output of it, is
there a
method to do it? All i have found is how to start a process (cmd /C),
but i
cannot retrieve the result of the command execution.

For example, it would be ideal if there would be a method like:

string result = ExecuteShellCommand("dir *.txt");

thnx in advance...


Nov 17 '05 #3
you probably need to set

myP.StartInfo.RedirectStandardOutput = true;

btw, if you only want to list out files, i would recommend the System.IO
namespace.

hth,
Dave
www.aspNetEmail.com

"Allan Rojas" <nd****@thecqgl.com> wrote in message
news:eN**************@TK2MSFTNGP12.phx.gbl...
I already did; but when executing the following code, i get a
System.InvalidOperationException: StandardOut has not been redirected.
System.Diagnostics.Process myP = System.Diagnostics.Process.Start("cmd",
@"/C dir C:\");
Response.Output.Write(myP.StandardOutput.ReadToEnd ());

Thnx in advance...
"dave wanta" <no****@nospam.com> wrote in message
news:O3*************@TK2MSFTNGP10.phx.gbl...
You want to look at the System.Diagnostics.Process namespace.
Cheers!
Dave
www.aspNetEmail.com

"Allan Rojas" <nd****@thecqgl.com> wrote in message
news:en**************@tk2msftngp13.phx.gbl...
Hi,

I want to execute a shell command and retrieve the output of it, is

there
a
method to do it? All i have found is how to start a process (cmd /C),

but
i
cannot retrieve the result of the command execution.

For example, it would be ideal if there would be a method like:

string result = ExecuteShellCommand("dir *.txt");

thnx in advance...



Nov 17 '05 #4

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

Similar topics

1
by: Bigbowser | last post by:
Hi all, I'm trying to create a sub shell environment ( i haven't really got a reason, its more of a test, although hopefully it will make life easier ;P ) but whenever i try to call the...
8
by: Siemel Naran | last post by:
Hi. I'm writing a command shell that reads commands from standard input. At this point I have the command in a std::string. Now I want to execute this command in the shell. From the Borland...
9
by: Amjad | last post by:
I'm trying to create a folder, append text file to another, and delete files using the "Shell" command. But I always get the error "File Not Found". How do I use DOS commands from Visual Basic?...
16
by: John Salerno | last post by:
Hi all. I just installed Ubuntu and I'm learning how to use the bash shell. Aside from the normal commands you can use, I was wondering if it's possible to use Python from the terminal instead of...
7
by: Bin Chen | last post by:
Hi, I want to do following: get a user input regex, then pass this as a parameter to grep, and then get the result from grep. Any code snip to implement the similar function? I am a python...
4
by: Anastasios Hatzis | last post by:
I'm looking for a pattern where different client implementations can use the same commands of some fictive tool ("foo") by accessing some kind of API. Actually I have the need for such pattern for...
1
by: Riccardo Maria Bianchi | last post by:
Hello! :) I'm trying to run shell commands both with os.system() and subprocess.Popen() class. But I can't run aliases or function defined in my .bashrc file, like in the login interactive...
1
by: raocheng | last post by:
Please see the following code. Suppose I have many shell commands to be executed. And I don't want to fork a sub shell for each command(eg: status,output = commands.getstatusoutput(cmd)) because...
5
by: inetquestion | last post by:
I am looking for a web interface for shell commands or shell scripts. Does anyone know of any exexisting php scripts which would solve this requirement? PHP form accepts input from a user, then...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.