The problem is that I need to execute a command in CMD, but since the paths of the files I search in Windows contain blank spaces, it requires me to use double quotes ("") to separate the paths.
When I call it from C # I try to "escape" the paths to embed the double quote, trying with @" "ruta" "
and " \"ruta\" "
. But it turns out that the final string drags the diagonal \"ruta\"
and is incorrect for the CMD interpreter.
Can I tell CMD to look for routes without using double quotes or how can I format the route for the command I prepare to send from C #?
The command to execute is similar to:
C:/Users/user/Documents/Sistema de Calidad/OfficeToPDF.exe
C:/Users/user/Documents/Sistema de Calidad/ + archivoEntrada
C:/Users/user/Documents/Sistema de Calidad/ + archivoSalida
It is worth mentioning that I can not rename the folders, because the project is very advanced and if I solve it locally it will also work on the production server whose folders also have spaces in their names.
Update:
The code that I left as tentative is the following.
string consulta = @"""C:/Users/user/Documents/Sistema de Calidad/bin/OfficeToPDF.exe"" " +
@" ""C:/Users/user/Documents/Sistema de Calidad/" + ruta + @""" " +
@" ""C:/Users/user/Documents/Sistema de Calidad/" + rutaSalida + @""" ";
EjecutarComando(consulta);
and Run command contains:
private void EjecutarComando(string comando)
{
try
{
var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = "/c " + comando,
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
proc.Start();
while (!proc.StandardOutput.EndOfStream)
{
string line = proc.StandardOutput.ReadLine();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
Greetings and thanks.