Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# How to use Directory White Spaces into process.arguements?

The program created utilizes a 3rd party tool to generate a log file.

However the arguments provided for the the tool requires various files from Directory locations as part of generating the logs. Therefore the main argument of @"-r C:\test\ftk\ntuser.dat -d C:\System Volume Information\" + restoreFolder.Name + " -p runmru"; would be used to generate the logs.

May someone advise on how to make the arguments of "C:\System Volume Information\" be processed by the system with the white spaces in placed? Thanks!

The codes:

            Process process = new Process();
            process.StartInfo.FileName = @"C:\test\ftk\ripxp\ripxp.exe";
            process.StartInfo.Arguments = @"-r C:\test\ftk\ntuser.dat -d C:\System Volume Information\" + restoreFolder.Name + " -p runmru";
            process.StartInfo.CreateNoWindow = false;
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardInput = true;
            process.StartInfo.RedirectStandardError = true;
            process.Start();
like image 831
JavaNoob Avatar asked Dec 14 '10 16:12

JavaNoob


2 Answers

You need to escape the " by appending a \ to them (\") - for normal strings, or doubling them ("") for verbatim string literals (those starting with @):

process.StartInfo.Arguments = @"-r C:\test\ftk\ntuser.dat -d ""C:\System Volume Information\" + restoreFolder.Name + @""" -p runmru";
like image 150
Oded Avatar answered Sep 23 '22 01:09

Oded


Wrap that path in double quotes:

process.StartInfo.Arguments = @"-r C:\test\ftk\ntuser.dat -d ""C:\System Volume Information\" + restoreFolder.Name + @""" -p runmru";
like image 23
decyclone Avatar answered Sep 26 '22 01:09

decyclone