-6

I can't seem to find a possible solution for entering 1 line of "command" into a CMD window. I searched the MSDN and asked google and they only found me solutions to enter text into a textfile, but that's not the same I guess.

Thank you in advance!

Richard
  • 3
  • 7
  • 1
    If you want to execute a command line, that's easy: `System.Diagnostics.Process.Start("cmd.exe", "/k dir /w/s");` I don't know about executing commands in *existing* cmd windows; is that an absolute requirement? – 15ee8f99-57ff-4f92-890c-b56153 Jan 25 '17 at 20:03
  • Yes since the cmd window has to be started with specific parameters. – Richard Jan 25 '17 at 20:06
  • And that can't be done if your application starts the process? – 15ee8f99-57ff-4f92-890c-b56153 Jan 25 '17 at 20:07
  • I don't know, the cmd window is getting started by a batchfile that sets the parameters, so i can't always start the application over and over, it's going to be kept running and commands need to be entered in the running state. – Richard Jan 25 '17 at 20:09
  • What do you mean, start the application over and over? – 15ee8f99-57ff-4f92-890c-b56153 Jan 25 '17 at 20:13
  • I have about 5 buttons with different commands for the application and I don't want to close the application and start it with a different command, I need to keep it running, basically it's a server. – Richard Jan 25 '17 at 20:16
  • What application? Your C# application? Why would you need to restart the application? – 15ee8f99-57ff-4f92-890c-b56153 Jan 25 '17 at 20:17
  • No, a Minecraft Server. The C# application is the least problem to close since I got config files :D – Richard Jan 25 '17 at 20:19
  • How is the batch file being ran? I may undelete my answer if you can launch `cmd.exe` yourself inside your c# program where you redirect StandardInput, then you use that window you opened yourself to launch the batch file, then you can send keys to it. – Quantic Jan 25 '17 at 20:21
  • 1
    It sounds to me like you're starting a Minecraft server via a batch file, and you want to write a .NET application that sends command line input to the Minecraft server programmatically, as if a user were typing them in at the keyboard. If that is not a complete description of your requirements, please write a full and complete description of exactly what you are trying to do, leaving out nothing, and put it in your question. These coy guessing games don't increase my interest in solving somebody's problem. – 15ee8f99-57ff-4f92-890c-b56153 Jan 25 '17 at 20:23
  • WoW :D Ok yeah sorry should've pointed my real problem out earlier, well, I'm going to change my Description then. Very sorry about that mistake. – Richard Jan 25 '17 at 20:25
  • 1
    Bear in mind that like most of the human race, I have never seen a Minecraft server and know precisely nothing about it, so you need to write your requirements so they make sense to somebody who knows absolutely nothing at all about any aspect of Minecraft whatsoever. Imagine your grandmother is a middle-aged software engineer with a short attention span who used to play Doom II. – 15ee8f99-57ff-4f92-890c-b56153 Jan 25 '17 at 20:25
  • Ok, this should fix it. – Richard Jan 25 '17 at 20:32
  • Do not replace your entire question text! This makes it very confusing to read responses to your original text. Ask a new question if you have a new question. – Blorgbeard Jan 25 '17 at 20:34
  • Ok, thanks Blorgbeard, new Question then – Richard Jan 25 '17 at 20:37

2 Answers2

0

You're going to have to start the Minecraft service process from your .NET application. Whatever you've got now in the batch file you're using, you can duplicate that in the Process start code in C#, or you can just have your C# code run the batch file.

If you want a config file providing startup parameters, you could put that stuff in app.config and have your application give them to the Minecraft server process on startup.

Once you've got the process started, your application can keep the Process object and send repeated commands to its standard input stream, as outlined in this answer.

Community
  • 1
  • 1
-1

System.Diagnostics.Process.Start("CMD.exe", [your command]);

Jan1902
  • 193
  • 1
  • 16