Jimbo James
Jimbo James

Reputation: 727

Running an exe from C# with arguments that have spaces in

I am scratching my head with this one. I am trying to run an exe from C# using system.diagnostics but it isnt passing over my arguments correctly so the exe falls over.

It splits the path after the word 'here' (see below) because of the space in it.

Does anyone know how I can get round this without renaming the directory (which isn't an option for me)

This works from command line:

"C:\Users\me\Desktop\myexternalexe\myexternalexe.exe" comments “\192.168.1.1\a\here is the problem\c\d\"

This doesn't from with in Visual Studio:

Process myexternalexe = new Process();

myexternalexe.StartInfo.FileName = @"C:\Users\me\Desktop\myexternalexe\myexternalexe.exe";
myexternalexe.StartInfo.Arguments = @"comments \\192.168.1.1\a\here is the problem\c\d\";

myexternalexe.Start();

Upvotes: 2

Views: 2779

Answers (3)

PSK
PSK

Reputation: 17943

Did you checked

this

In your case following should work.

 string folderName = @"\\192.168.1.1\a\here is the problem\c\d\";
 myexternalexe.StartInfo.Arguments= @"comments" + " \"" + folderName  +"\"";  

Upvotes: 1

InBetween
InBetween

Reputation: 32750

Have you tried:

 alexe.StartInfo.Arguments = "comments \"\\\\192.168.1.1\\a\\here is the problem\\c\\d\\\"";

Upvotes: 0

Tim Rogers
Tim Rogers

Reputation: 21713

But you've omitted the quotes from the C# version. It should be:

myexternalexe.StartInfo.Arguments = @"comments ""\\192.168.1.1\a\here is the problem\c\d\""";

Upvotes: 7

Related Questions