从 Linux 调用 Windows 批处理文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/238013/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Invoking windows batch file from Linux
提问by Ragoler
I have an application running only on Windows and a batch file that launches it. 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.
我有一个仅在 Windows 上运行的应用程序和一个启动它的批处理文件。我想从 Linux 调用这个批处理文件,这意味着像 Linux 批处理这样的东西将启动带有参数的 Windows 批处理,然后依次运行我的应用程序。
Can I do that? How?
我可以这样做吗?如何?
回答by dsm
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 框中启动您的应用程序。
回答by Andru Luvisi
The most direct way is probably to install an ssh server on the windows box. Cygwinincludes an ssh server.
最直接的方法大概就是在windows box上安装一个ssh服务器。 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. Then you could use Samba/smbclient to create the file. You would need to turn on filesharing on the windows box for this to work.
根据您的计时需求的精确程度,您可能能够在 windows 框上有一个“at”作业,该作业定期运行(每 5 分钟一次?),并在发现特定文件存在时运行,删除该文件。然后您可以使用Samba/smbclient 创建该文件。您需要在 Windows 框中打开文件共享才能使其正常工作。
If the windows box has a web server, you could write a CGI, and trigger it using wgetor cURL.
回答by Mrchief
回答by Peter K.
回答by Aleksey Otrubennikov
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. This can be a web-server for example. And then invoke your process inside PHP/Perl/Python script.
更安全的方法是在 Windows 计算机上设置服务器。例如,这可以是一个网络服务器。然后在 PHP/Perl/Python 脚本中调用您的进程。