0

Call command in c#

How can you call a command of cmd in c#? Like you do os.system("dir") in python?

25th May 2020, 9:56 AM
AtomicxJS
AtomicxJS - avatar
8 odpowiedzi
0
Here's a link to a similar question: https://stackoverflow.com/questions/206323/how-to-execute-command-line-in-c-get-std-out-results It almost sounds like you are trying to run python code from C#, and get the standard out. That link should help you.
25th May 2020, 10:51 AM
Matthew Shoop
Matthew Shoop - avatar
0
You want to use System.Diagnostics.Process.Start("cmd.exe", yourCommandHere); Edit: The more I think about this, the more I think you may want to use something from AppDomain and not send commands to the command prompt. What are you trying to do?
25th May 2020, 10:26 AM
Matthew Shoop
Matthew Shoop - avatar
0
Matthew Shoop, this brings up a window
25th May 2020, 10:36 AM
AtomicxJS
AtomicxJS - avatar
0
Yes it does. Which is why I think you don't actually want to pass commands to cmd. Try System.IO.Directory.GetFiles instead of dir.
25th May 2020, 10:41 AM
Matthew Shoop
Matthew Shoop - avatar
0
I am trying to do two custom commands. 1) One that will do some calculation and save it to a file. 2) Another one which I will need to read from cmd.
25th May 2020, 10:44 AM
AtomicxJS
AtomicxJS - avatar
0
So you are using the File class to write to your file. Now you just need to read cmd output from what command? There is almost certainly a class for it.
25th May 2020, 10:47 AM
Matthew Shoop
Matthew Shoop - avatar
0
No, there is two different commands I made in other languages.
25th May 2020, 10:48 AM
AtomicxJS
AtomicxJS - avatar
0
It works! Thanks!
25th May 2020, 11:21 AM
AtomicxJS
AtomicxJS - avatar