Can't Run Go Exe from C# like I can Manually in the CMD

Hi Folks,

I hope everyone is well and trying to stay healthy.

So I’m pulling my hair out, not much left. Problem…

1.) I have a built and installed Go executable call it “xray.exe” in my C:\User\Go\Bin directory.

I have no issues opening up the windows command prompt, changing to that directory and running it like so…
executable file name < “inputfilepath” > “outputfilepath”
xray.exe < “C:\file Input path\FileIn.txt” > “D:\File Out Path\FileOutput.txt”

Simply, I am trying to run this executable file via a C# project (to automate the "heavey lifting of a large number of files), I’ve tried (in C#) running the exe directly using process and/or indirectly by trying to run it thru CMD in C#. I can’t for the life of me get it to work. I can only surmise or guess it has something to do with correctly formatting process.info fields and how to correctly mimic the passing of the args. Also I’m not sure if I should use these “<” and “>” “things” that I seem to have to use when doing it manually by opening up and running it in the command window.

Please help. Let me that you for the assistance in advance.

Be well and stay safe.
Best,
-S

Normally a Go program reads standard input from the keyboard and writes standard output to the console. The < and > commands mean to redirect standard input and standard output, respectively. By using them, you are substituting the contents of the file “C:\file Input path\FileIn.txt” for the keyboard and writing the output to “D:\File Out Path\FileOutput.txt”.

At this point your question becomes a C# / .NET question, not a Go question. You might find help by reviewing Microsoft’s documentation on the ProcessStartInfo.RedirectStandardInput property and the ProcessStartInfo.RedirectStandardOutput property.

Alternatively, you could modify your Go program to obtain the names of the input and output files from the program arguments and then open those files directly. See os.Args. In this case to supply those arguments from C# you would use the ProcessStartInfo.Arguments property.

Hi Fineol,

Thank you for the gracious help!

Regarding ProcessStartInfo.Arguments property, that is what I’m trying to use. I just don’t know how to format the Args. For example, what is the exe expecting (given my example), For example do I have to include the < and >? Does the exe parse the arg string by spaces so that the standard input and output strings (if they contains spaces) would have to be enclosed in Quotes? If I have to pass the < and >, would they be picked up only separated by spaces on either side like " < " etc?

I’m just trying to format the Arguments correctly for the exe and mimic how I do it manually from the CMD prompt or at least how the exe sees it and the format that it expects.

Thoughts?

Thanks again!
-S