473,545 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

options for shelling out command line commands

djc
I'm wondering what options are available, if any, for being able to run 'any
command line command' from a .net compiled program. I would want the output
that would normally go to the command line for the command to be available
to my program.

I know from even very old VB that you can 'shell' out and run programs, one
of which could be for example, cmd.exe with specific command but I don't
know that you could get the actual command results (other than an exit, or
return code). Plus, before I go 'shelling out' I wanted to see if there is a
'newer' way of doing this. Maybe something more builtin like a class that
actually exposes an interface to send standard shell commands to and returns
the results to you in code? The actual output that would appear on the
screen if you had run the command from the command line.

eg.
myVariable = SomeCoolClass.E xecShellCmd("di r c:")

and the directory listing for c: would be a string in myVariable (including
white space chars to preserve formatting)

anyone know of anything like this? Buitlin to .net already?
Feb 8 '06 #1
6 1304
Hello djc,

The only way is to redirect output of the console program to file and read
result afterwards

d> I'm wondering what options are available, if any, for being able to
d> run 'any command line command' from a .net compiled program. I would
d> want the output that would normally go to the command line for the
d> command to be available to my program.
d>
d> I know from even very old VB that you can 'shell' out and run
d> programs, one of which could be for example, cmd.exe with specific
d> command but I don't know that you could get the actual command
d> results (other than an exit, or return code). Plus, before I go
d> 'shelling out' I wanted to see if there is a 'newer' way of doing
d> this. Maybe something more builtin like a class that actually exposes
d> an interface to send standard shell commands to and returns the
d> results to you in code? The actual output that would appear on the
d> screen if you had run the command from the command line.
d>
d> eg.
d> myVariable = SomeCoolClass.E xecShellCmd("di r c:")
d> and the directory listing for c: would be a string in myVariable
d> (including white space chars to preserve formatting)
d>
d> anyone know of anything like this? Buitlin to .net already?
d>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Feb 8 '06 #2
djc wrote:
I'm wondering what options are available, if any, for being able to
run 'any command line command' from a .net compiled program. I would
want the output that would normally go to the command line for the
command to be available to my program.


Use the "RedirectStanda rdOut" property. See:

http://www.srtsolutions.com/public/item/105222

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Feb 8 '06 #3
You don't have to redirect to a file. When using the Process class,
you can redirect the output of the console program to a stream and then
just read that stream to get the output from the program.

Feb 8 '06 #4
djc
thats one way I was thinking could work. That or creating an environment
variable to redirect to and subsequently retrieve from.

thanks for the reply.

"Michael Nemtsev" <ne*****@msn.co m> wrote in message
news:9c******** *************** ***@msnews.micr osoft.com...
Hello djc,

The only way is to redirect output of the console program to file and read
result afterwards

d> I'm wondering what options are available, if any, for being able to
d> run 'any command line command' from a .net compiled program. I would
d> want the output that would normally go to the command line for the
d> command to be available to my program.
d>
d> I know from even very old VB that you can 'shell' out and run
d> programs, one of which could be for example, cmd.exe with specific
d> command but I don't know that you could get the actual command
d> results (other than an exit, or return code). Plus, before I go
d> 'shelling out' I wanted to see if there is a 'newer' way of doing
d> this. Maybe something more builtin like a class that actually exposes
d> an interface to send standard shell commands to and returns the
d> results to you in code? The actual output that would appear on the
d> screen if you had run the command from the command line.
d>
d> eg.
d> myVariable = SomeCoolClass.E xecShellCmd("di r c:")
d> and the directory listing for c: would be a string in myVariable
d> (including white space chars to preserve formatting)
d>
d> anyone know of anything like this? Buitlin to .net already?
d>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not cease to be insipid." (c) Friedrich Nietzsche

Feb 8 '06 #5
djc
that sounds perfect! Thanks.

are you refering to the same class as Patrick Steele is in his reply to this
post?
System.Diagnost ics.Process AND System.Diagnost ics.ProcessStar tInfo?

I'll check this out tomorrow, I just wanted to clarify these are the same
solution and not 2 different ones.
"Chris Dunaway" <du******@gmail .com> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.com...
You don't have to redirect to a file. When using the Process class,
you can redirect the output of the console program to a stream and then
just read that stream to get the output from the program.

Feb 8 '06 #6
djc
thank you!

"Patrick Steele" <patrick_at_mvp s*dot*org> wrote in message
news:ey******** ******@TK2MSFTN GP15.phx.gbl...
djc wrote:
I'm wondering what options are available, if any, for being able to
run 'any command line command' from a .net compiled program. I would
want the output that would normally go to the command line for the
command to be available to my program.


Use the "RedirectStanda rdOut" property. See:

http://www.srtsolutions.com/public/item/105222

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele

Feb 8 '06 #7

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

Similar topics

12
1821
by: Rich | last post by:
Hello, I would like to turn on/invoke a VB6 app which resides on the server/folder where IIS is running from an ASP page. As for security, this would be all happening within an intranet with firewall protection, etc, no outside internet access. In pseudocode of my asp app I am thinking like this: <%
3
5279
by: Florian | last post by:
I need to set multiple values for some SQL statements, for example SET NUMERIC_ROUNDABORT OFF GO SET ANSI_PADDING,ANSI_WARNINGS,CONCAT_NULL_YIELDS_NULL,ARITHABORT,QUOTED_IDENTIF IER,ANSI_NULLS ON GO in a .sql file, but would like to reset them to their previous settings
0
1211
by: gatti | last post by:
When building a C extension, Distutils standard command 'install' calls the 'build' command before performing the installation (see Lib/distutils/command/install.py and build.py). Reusing the build command is the correct way to ensure the installation payload is ready, but the two commands support very different sets of user options and it is...
1
1494
by: A | last post by:
Does anyone have any code for shelling out a command to start up an executable with command line arguments? I am simply trying to start a MSDE install by calling its Setup.exe. Thanks
34
6822
by: Roman Mashak | last post by:
Hello, All! I'm implementing simple CLI (flat model, no tree-style menu etc.). Command line looks like this: <command> <param1> <param2> ... <paramN> (where N=1..4) And idea is pretty simple: 1) get whole string of input line 2) preset table of strings matching <command> 3) preset table of function calls
0
1220
by: MirkoGeest | last post by:
(Webmaster: sorry, I posted this first at the General Software Engineering category, but I think this goes here) I'm using Visual Basic with Web Forms on .NET 2003 and I'm experiencing a very weird problem: When the user presses a button, the web application starts a shell process to decompress a *.gz file with gzip.exe. All ok for now, I...
8
8607
by: 4.spam | last post by:
Hello. WinXP, db2 v8.2.7 When I use UPDATE COMMAND OPTION USING <any_switchON(or OFF) it seems that this command has absolutely no effect on these switches since command LIST COMMAND OPTIONS issued after that shows the same values as before issuing UPDATE
3
4798
by: ManningFan | last post by:
Due to the way our IT group has set up our servers, we are not allowed to use the Shell() command. We are already doing a similar action with an FTP command. Our code is thus: sExe = Environ$("COMSPEC") sExe = Left(sExe, Len(sExe) - Len(Dir(sExe))) sExe2 = sExe & "ftp.exe -s:" & Q & sScrFile & Q
8
2593
by: evenlater | last post by:
I have an .accde file with custom ribbons and with "Allow Full Menus" set to False, but the Office Button menu still gives the user the ability to create a new Access database, or -- much worse -- open an existing one. My application is on a terminal server and I'm trying to plug all the holes so the user can't do anything but use my...
0
7484
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7415
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...
0
7675
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. ...
1
7440
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7775
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...
0
5997
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...
0
3470
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...
0
3451
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1902
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

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.