简体   繁体   English

从Linux调用Windows批处理文件

[英]Invoking windows batch file from Linux

I have an application running only on Windows and a batch file that launches it. 我有一个只在Windows上运行的应用程序和一个启动它的批处理文件。 I want to invoke this batch file from Linux, meaning something like Linux batch will launch the windows batch with parameters and this in its turn run my application. 我想从Linux调用这个批处理文件,这意味着像Linux批处理这样的东西会启动带有参数的windows批处理,而这又会运行我的应用程序。

Can I do that? 我能这样做吗? How? 怎么样?

You could install an ssh server in the windows box (Cygwin has one), then from linux do something like: 你可以在windows框中安装一个ssh服务器(Cygwin有一个),然后从linux执行以下操作:

ssh user@windows-box c:/path/to/batch.cmd

and that should launch your application in the windows box. 这应该在Windows框中启动您的应用程序。

The most direct way is probably to install an ssh server on the windows box. 最直接的方法可能是在Windows机器上安装ssh服务器。 Cygwin includes an ssh server. Cygwin包含一个ssh服务器。

Depending on how precise your timing needs are, you might be able to have an "at" job on the windows box that runs periodically (every 5 minutes?) and runs if it sees that a particular file exists, deleting the file. 根据您的计时需求的精确程度,您可以在Windows框上定期运行(每5分钟一次?)并在运行时看到特定文件存在,并删除该文件。 Then you could use Samba /smbclient to create the file. 然后,您可以使用Samba / smbclient来创建文件。 You would need to turn on filesharing on the windows box for this to work. 您需要在Windows框中打开文件共享才能使用此功能。

If the windows box has a web server, you could write a CGI , and trigger it using wget or cURL . 如果Windows框具有Web服务器,您可以编写CGI ,并使用wgetcURL触发它。

另请参阅winexe ,它允许您在不运行ssh服务器的情况下执行Windows命令/批处理脚本。

Our build process currently goes the other way: a windows sever kicks off things on the Linux server using plink (part of PuTTY ). 我们的构建过程目前采用另一种方式:Windows服务器使用plink( PuTTY的一部分)启动Linux服务器上的东西。 You might be able to set something similar up. 你可以设置类似的东西。

This may cause a security issue. 这可能会导致安全问题。 Our information security person did not allow me to invoke any programs directly. 我们的信息安全人员不允许我直接调用任何程序。

The safer way is to set up server on Windows computer. 更安全的方法是在Windows计算机上设置服务器。 This can be a web-server for example. 例如,这可以是Web服务器。 And then invoke your process inside PHP/Perl/Python script. 然后在PHP / Perl / Python脚本中调用您的进程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM