Generalized "Scripting" Functions from C#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to be able to execute (and access the return codes from) command-line shell functions in my command-line C# EXE. How do I do this? I want to be able to do everything from an XCOPY to NET START stuff. I know that some of these things could be done using intrinsic framework objects but it seems so much easier to do a lot of this stuff this way. How do I do it?
 
Have a look at the Process class, it allows you to start other applications.

If possible I would have used the .NET supported features, it's a lot easier
to catch an exception than handling an exit code and then possibly parse the
application output.


Chris


Alex Maghen said:
I want to be able to execute (and access the return codes from)
command-line shell functions in my command-line C# EXE. How do I do this? I
want to be able to do everything from an XCOPY to NET START stuff. I know
that some of these things could be done using intrinsic framework objects
but it seems so much easier to do a lot of this stuff this way. How do I do
it?
 
Two things in response to your response (which, by the way, I appreciate):

1. Doing things like 'MyProcess.StartInfo.FileName = "notepad"; MyProcess.Start();' works fine. But it there any way to execute something real simple and DOS-like such as 'MyProcess.StartInfo.FileName="xcopy /?"; MyProcess.Start(); I get an error: "An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in system.dll".

2. You suggested not trying to do things this way and using .NET functions themselves. Is there any kind of authoritative document describing the "replacement functions" for nice, simple DOS stuff within the framework? LIKE FOR EXAMPLE, HOW DO I GET THIS INCREDIBLY EASY FUNCTIONALITY OF XCOPY INSIDE .NET???

Thanks!

Alex
 
"=?Utf-8?B?QWxleCBNYWdoZW4=?=" <[email protected]>
wrote in
'MyProcess.StartInfo.FileName="xcopy /?"; MyProcess.Start(); I get an
error: "An unhandled exception of type
'System.ComponentModel.Win32Exception' occurred in system.dll".

This is because you have no file on your disk named "xcopy /?".

Try separating out "/?" to the arguments property and leave the filename
property containing only the name of the file to execute.

within the framework? LIKE FOR EXAMPLE, HOW DO I GET THIS INCREDIBLY
EASY FUNCTIONALITY OF XCOPY INSIDE .NET???

You build it using a recursive copying method :)
 
Back
Top