2012-04-11 124 views
2

我在遠程機器上有一個.bat文件。我想通過http調用來調用它。我不想在遠程機器上進行任何更改。有沒有辦法使用java和http做到這一點?通過http調用遠程.bat文件

String command = "cmd /C start C:/Users/abc/Desktop/test.bat"; 
Runtime rt = Runtime.getRuntime(); 
Process pr = rt.exec(command); 

上述工作很好地調用本地機器上的.bat文件。我也不介意考慮其他方式,但通過http調用它將是第一選擇。

編輯: 我現在使用paramiko來做到這一點。但是,我無法在命令提示符下運行遠程命令。

ssh = paramiko.SSHClient() 

print "Enter the IP address" 
ip = raw_input("ip>") 
print "Enter the username" 
user = raw_input("username>") 
print "Enter the password" 
pwd = raw_input("password>") 

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 
ssh.connect(ip, username=user, password=pwd, allow_agent = False) 
print "connection successfull" 
i, o, e = ssh.exec_command("echo test") # example command 
s = e.read() 
if s: # an error occurred 
    raise RuntimeError, s 
result = o.read() 
print result 

不知怎的,它說AllowDesktopAccess失敗

回答

4

您需要的服務在遠程機器上,例如被配置爲按需運行該腳本的HTTP服務器(例如,通過CGI)或SSH服務器您可以連接到發出命令。

由於您使用Windows(我假設),那麼PsExec可能是您需要的服務。

http://technet.microsoft.com/en-us/sysinternals/bb897553