473,387 Members | 3,033 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,387 software developers and data experts.

Running shell commands in c#

Hello all. This topic has been covered on google groups before, but I
couldn't find a good response.

I have a shell command I wish to execute from c# (or vb or your
favorite .net language). I know the relevant class is
System.Diagnostics.Process.
The problem is that I don't know the name of the exe (or bat, or
whatever) of the process. This seems to be a requirement for the
Process class. All I have is a string (which is the command I want to
execute).

So let's say the string is
myCommand c:\*.* > c:\temp\crap.txt
and assume I don't know where myCommand is (perhaps its path is in the
PATH system var). That is, even if I could parse the command, it
wouldn't help. I'm not quite willing to look up environment variables
just now. (In my case, myCommand is dir, but that's not the point).

How do I go about executing this?
My current solution of writing a perl script and passing the command as
a param seems ridiculous, although perl handles it well.

Thanks ahead of time,
Michael Kamzyuk

Nov 22 '05 #1
1 8124
intrinsic commands, like dir, are not programs. They are commands of the
command shell. You would execute them by executing a command shell process
(cmd.exe) and passing the command to it.

Therefore, your command is:
cmd.exe /c dir

To see a complete listing of information on using the command processor,
drop to the command prompt and enter:
cmd /?
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Mike Kamzyuk" <Mi*********@hotmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Hello all. This topic has been covered on google groups before, but I
couldn't find a good response.

I have a shell command I wish to execute from c# (or vb or your
favorite .net language). I know the relevant class is
System.Diagnostics.Process.
The problem is that I don't know the name of the exe (or bat, or
whatever) of the process. This seems to be a requirement for the
Process class. All I have is a string (which is the command I want to
execute).

So let's say the string is
myCommand c:\*.* > c:\temp\crap.txt
and assume I don't know where myCommand is (perhaps its path is in the
PATH system var). That is, even if I could parse the command, it
wouldn't help. I'm not quite willing to look up environment variables
just now. (In my case, myCommand is dir, but that's not the point).

How do I go about executing this?
My current solution of writing a perl script and passing the command as
a param seems ridiculous, although perl handles it well.

Thanks ahead of time,
Michael Kamzyuk

Nov 22 '05 #2

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

Similar topics

0
by: Will Seay | last post by:
At the end of this message I've pasted a script we're trying to modify slightly. I don't believe it is VBscript or javascript but these are the closest groups I could find with my limited...
3
by: Hal Vaughan | last post by:
I need to be able to run external commands from within a Java program, on Linux and Windows (and eventually OSX). Under most circumstances there is no problem, but if the path I specify as part of...
1
by: Mike Kamzyuk | last post by:
Hello all. This topic has been covered on google groups before, but I couldn't find a good response. I have a shell command I wish to execute from c# (or vb or your favorite .net language). I...
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...
0
by: paulhjwu | last post by:
Hi, I have problems running a couple of shell scripts from PHP. I found a similar posting, so I posted my question to the original author. But unfortunately the original author is not at the...
11
by: Gregor Kovač | last post by:
Hi! I have an SQL script with bunch of CREATE TABLES, ALTER TABLES, ... I'd like it to run transactially. I have found that id I run a ALTER STATEMENT inside a transaction and then roll it back...
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...
3
by: R. Bernstein | last post by:
The next release of pydb will have the ability to go into ipython from inside the debugger. Sort of like how in ruby-debug you can go into irb :-) For ipython, this can be done pretty simply;...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.