本文介绍了如何将命令发送到通过批处理命令行运行的 EXE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 TerrariaServer.exe 的服务器应用程序正在运行,我希望能够使用单独的批处理文件向它发送命令.TerrariaServer.exe 是一个作为命令行运行的程序.我怎么能喂"它一个诸如保存"和退出"之类的命令?答案可能是管道,但我不太确定.这是我在 TerrariaServer.exe 运行时在批处理文件中执行的内容...

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.

推荐答案

哎呀,多行输入使用type!

echo save | TerrariaServer.exe

将打开 TerrariaServer.exe 并将保存"作为输入发送给它.

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

echo exit | TerrariaServer.exe

将打开 TerrariaServer.exe 并将exit"作为输入发送给它.

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

看到问题了吗?:P

您正在执行 TerrariaServer.exe 两次

You're executing TerrariaServer.exe twice!

你应该使用命令type.您可以在可执行文件的输入中键入文本文档.首先,让我们创建这个文本文档(或任何文件;扩展名无关紧要!)

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

现在让我们在 TerrariaServer.exe 中输入它...

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

type somefile.txt | TerrariaServer.exe

也许在我们完成后删除 somefile.txt?

Maybe delete somefile.txt after we're done?

del somefile.txt

希望能把事情弄清楚!:)

Hope that cleared things up! :)

这篇关于如何将命令发送到通过批处理命令行运行的 EXE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-19 08:31