Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Execute Process With Parameters
    text
    copied!<p>I am new to .bat files. I have a file containing these lines:</p> <pre><code>cd %~dp0 pat\to\dot.exe -Tsvg -o -Kdot %~n1.txt &gt; %~.svg </code></pre> <p>These lines will call <code>dot.exe</code> which will take the inputted text file and parse it into a .svg with some content. Currently I drag the .txt file on to the .bat with the code above to create the svg. I don't really know what <code>%~dp0</code> changes the directory to the current drive, I will have to move the file after I generate as well. I know <code>%~n1</code> represents the file path of the first argument.</p> <p>I want to run these two commands through c# using the command shell. the code below will generate the .svg file but it wont contain any data. I am assuming that is because the argument is not getting passed in correctly, but I am not really sure how to add it. Any suggestions?</p> <pre><code>[STAThread] static void Main() { string name = "file.txt"; ProcessStartInfo psi = new ProcessStartInfo(@"C:\WINDOWS\system32\cmd.exe"); psi.UseShellExecute = false; psi.ErrorDialog = false; psi.CreateNoWindow = true; psi.WindowStyle = ProcessWindowStyle.Hidden; psi.RedirectStandardError = true; psi.RedirectStandardInput = true; psi.RedirectStandardOutput = true; //I am not sure if this will actually attach the argument to the WriteLine() or not psi.Arguments = name; Process wgsProcess = new Process(); wgsProcess.StartInfo = psi; wgsProcess.Start(); StreamWriter inputWriter = wgsProcess.StandardInput; StreamReader outputReader = wgsProcess.StandardOutput; StreamReader errorReader = wgsProcess.StandardError; inputWriter.WriteLine("cd %~dp0"); inputWriter.Flush(); inputWriter.WriteLine(" pat\to\dot.exe -Tsvg - o - Kdot " + name + " &gt; " + name + ".svg"); inputWriter.Flush(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload