Running a DOS program with parameters.

U

UJ

I got help from somebody here telling me how to run a DOS command using the
process variable. Problem for me is that I need to be able to pass
parameters to the program - multiple parameters at that. When I run the full
command line, which looks something like:

"C:\Program Files\ABC Amber Text2Image Converter\abct2img.exe"
"C:\LeftPanel.htm" "C:\LeftPanel.jpg" 0 5"

If I run the command from a command prompt it works fine. But if I run it
through the process command is get an exception with a "The system cannot
find the file specified" error.

Anybody have any ideas on what I can do?

Could I create a batch file and run that?

TIA - Jeffrey.
 
M

Morten Wennevik

Hi Jeffrey,

You need to separate the executable and the parameters in two strings.

string exec = "C:\Program Files\ABC Amber Text2Image Converter\abct2img.exe";
string params = "C:\LeftPanel.htm C:\LeftPanel.jpg 0 5";

Process.Start(exec, params);
 
C

Chris Dunaway

Morten said:
string exec = "C:\Program Files\ABC Amber Text2Image Converter\abct2img.exe";
string params = "C:\LeftPanel.htm C:\LeftPanel.jpg 0 5";

Oops! You need to place a @ sign on the front of those strings
otherwise the slashes (\) will serve as an escape character:

string exec = @"C:\Program Files...."
string params = @"C:\LeftPanes.htm......"
 
U

UJ

I'm doing it in VB.Net so I don't need the @ signs. Or at least I don't
think I need it. I'll try it anyway.
 
U

UJ

Looks like I don't need to @ command (and I can't seem to find it anywhere
in the VB documentation.) but if I look at the variables they look fine -
they contain the values they are supposed to. I also tried replacing all of
the \ with \\ and it still doesn't seem to work.

I'll keep trying......

TIA.
 
U

UJ

My continuing saga......

Ah - the plot thickens.....I did exactly the same code in a VB.Net console
app and it worked fine. But I'm trying to do it via code behind in an
ASP.Net page. Looks like it's a security issue.

My ASPNET user is a member of Administrators so I don't see what that can
be. And it's already creating files in the directory so I know that's not an
issue.

Anybody got an idea of how to fix it?

TIA - Jeffrey.

I don't know if it makes any difference but I'm
 
M

Morten Wennevik

Do you still get the same error with file not found? If so, the file is probably in another place.
 
U

UJ

Thanks everybody for your help. I finally got it working - only to have it
turn out that the program I'm calling (a third party program) doesn't play
nice so I'm taking a different tack.

Thanks again - Jeffrey.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top