How do I send commands to an EXE running through the command line with batch?

拜拜、爱过 提交于 2019-11-30 19:15:40

问题


I have a server application running called TerrariaServer.exe and I want to be able to send it commands with separate batch file. TerrariaServer.exe is a program running as a command line. How could I "feed" it a command such as "save" and "exit"? The answer might be pipes, but I'm not too sure. Here is kinda what I executed in a batch file while TerrariaServer.exe was running...

@echo off
echo save | TerrariaServer.exe
echo exit | TerrariaServer.exe

After that, nothing happen. I don't know if you need to know this but this is a video game server and the "save/exit" commands come with it.


回答1:


Eep, use type for multiline input!

echo save | TerrariaServer.exe

will open up TerrariaServer.exe and send "save" as input to it.

echo exit | TerrariaServer.exe

will open up TerrariaServer.exe and send "exit" as input to it.

See the problem yet? :P

You're executing TerrariaServer.exe twice!

You should use the command type. You can type a text document into the input of an executable. First, let's create this text document (or any file for that matter; the extension doesn't matter!)

echo save>somefile.txt
echo exit>somefile.txt

Now let's type this into TerrariaServer.exe...

type somefile.txt | TerrariaServer.exe

Maybe delete somefile.txt after we're done?

del somefile.txt

Hope that cleared things up! :)



来源:https://stackoverflow.com/questions/13832786/how-do-i-send-commands-to-an-exe-running-through-the-command-line-with-batch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!