Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 如何向正在运行的程序发送命令?批处理文件_Batch File - Fatal编程技术网

Batch file 如何向正在运行的程序发送命令?批处理文件

Batch file 如何向正在运行的程序发送命令?批处理文件,batch-file,Batch File,我有一个名为myProgram.exe的程序,它正在服务器的控制台中运行。在服务器上,我可以在控制台中键入一个命令,它就可以工作了。 在客户端,我如何使用批处理文件将命令发送到此控制台。我想连接到这个控制台,并通过一行命令传递给它。有可能吗 服务器:Windows2003服务器 客户端:Windows XP或Win7您可能希望使用PSEXEC(系统内部) 使用remote.exe的详细解决方案 在服务器“A”上: remote/s cmd bootSession 在客户端“B”上: create

我有一个名为myProgram.exe的程序,它正在服务器的控制台中运行。在服务器上,我可以在控制台中键入一个命令,它就可以工作了。
在客户端,我如何使用批处理文件将命令发送到此控制台。我想连接到这个控制台,并通过一行命令传递给它。有可能吗

服务器:Windows2003服务器
客户端:Windows XP或Win7

您可能希望使用PSEXEC(系统内部)


使用
remote.exe的详细解决方案

在服务器“A”上:
remote/s cmd bootSession

在客户端“B”上:
createSession.bat

@echo off
echo remote /s cmd session1 > commands.txt
echo @q >> commands.txt
remote /c A bootSession < commands.txt
del commands.txt
remote /c A session1
@echo关闭
echo remote/s cmd session1>commands.txt
echo@q>>commands.txt
远程/c启动会话
如果您考虑使用多个会话,则应在客户端上运行计数器,并在
uid
中嵌入客户端名称+计数器


您也可以创建随机uid。

我已经修改了客户端B中的代码createSession.bat:

@echo off
echo remote /s cmd session1 > commands.txt
echo @Q >> commands.txt
runas /profile /savecred /user:User1"cmd /C %RemotePath%\remote /c computerA bootSession   < %CD%\commands.txt" 
runas /profile /savecred /user:User1"cmd /k %RemotePath%\remote /c computerA session1"  
@echo关闭
echo remote/s cmd session1>commands.txt
echo@Q>>commands.txt
runas/profile/savecred/user:User1“cmd/C%RemotePath%\remote/C computerA引导会话<%CD%\commands.txt”
runas/profile/savecred/user:User1“cmd/k%RemotePath%\remote/c computerA session1”
它工作正常,但cmd(bootSession)的第一个实例仍然打开,即使我将@Q发送到remote退出。您可以关闭它,让它只运行第二个实例(会话1)


再次感谢

这可以在那里执行程序,而不是向它发送命令。如果程序基于cmd guiRight,这将有助于您从客户端托管您的程序,您必须再次阅读他的问题2次才能得到他想要的。哈!这就是我正在做的。我想更换psexec工具,因为我们没有权限将其与我们的产品一起分发。我认为不可能向Windows控制台中运行的程序发送命令(第一个响应在哪里?)。谢谢你的帮助,我用remote.exe工具替换了psexec,在这个例子中,他们使用KD或CDB,我使用cmd而不是TANKS,它可以工作,只是在第二行echo remote/s cmd session1>commands.txt中。我尝试过这个方法,但不起作用:runas/profile/savecred/user:User1“cmd/C(%RemotePath%\remote/C computerA bootSession<%CD%\commands.txt)&exit”很抱歉回答晚了。我没有看到你发布了另一个问题作为答案!代码的问题是,您不再从commands.txt向remote.exe提供stdin,但runas wich不会将其解析到它的子进程。尝试从批处理文件中删除运行方式,而不是通过运行方式调用批处理文件。我使用了:taskkill/f/fi“WINDOWTITLE eq Remote/C ComputerB”“bootSession”“”/TSo是否要关闭cmd的“bootSession”实例?然后您可以在
echo@q>commands.txt
之前添加一个
echo exit>commands.txt
。。。
@echo off
echo remote /s cmd session1 > commands.txt
echo @Q >> commands.txt
runas /profile /savecred /user:User1"cmd /C %RemotePath%\remote /c computerA bootSession   < %CD%\commands.txt" 
runas /profile /savecred /user:User1"cmd /k %RemotePath%\remote /c computerA session1"