在 unix 中运行 .bat 脚本 [英] Run .bat script in unix

查看:47
本文介绍了在 unix 中运行 .bat 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Windows 共享上有一个 .bat 脚本,它安装在我的 UNIX 机器上.Bat 脚本设置为在 2 个 Windows 共享之间进行文件传输,但如果可能的话,我想从 unix 机器触发此脚本.我读到你可以用 wine 或 dosbox 来做,但我的 unix 上没有安装它.是否可以使用一些额外的 .sh 脚本来解决这个问题,以正确触发我的 .bat 脚本?

I have one .bat script on my windows share that is mounted to my UNIX machine. Bat script is set to make file transfer between 2 windows shares, but I would like to trigger this script from a unix machine if that is possible. I was reading that you can do it with wine or dosbox, but I don't have that installed on my unix. Is it possible to resolve this problem with some additional .sh script that will trigger my .bat script correctly?

先谢谢你.此致.

推荐答案

您不能运行 .bat 脚本 在 Unix 机器上有几个原因:

You cannot run a .bat script on a Unix machine for several reasons :

  • Unix 的命令(在命令行上)与 Windows 不同.POSIX 标准定义了一组命令,如果您使用它们,您将可以在各种POSIX 系统(但不在 Windows 上);例如要列出目录,您将使用DIR 在 MSDOS 和 Windows 上,但 ls 在 Unix 和 POSIX 上;复制文件在 MSDOS 和 Windows 上是 COPY,在 Unix 和 POSIX 上是 cp;等等....

  • Unix has not the same commands (on the command line) as Windows. The POSIX standard defined a set of commands, if you use them you'll be portable on various POSIX systems (but not on Windows); for example to list a directory, you'll use DIR on MSDOS and Windows but ls on Unix and POSIX; to copy a file it is COPY on MSDOS and Windows but cp on Unix and POSIX; etc....

Unix 与 命令解释器不同视窗.POSIX 标准和 Unix 传统提供了一个 Unix shell 并且 POSIX 有 标准化 /bin/sh(又名 POSIX shell).Windows 有 CMD(从 MSDOS 继承)和 PowerShell.

Unix has not the same command interpreter as Windows. The POSIX standard and the Unix tradition provides a Unix shell and POSIX has standardized /bin/sh (a.k.a. POSIX shell). Windows has CMD (inherited from MSDOS) and PowerShell.

解释命令的方式不同(在 Windows 上也可以查看 PowerShell,我不知道).在 Unix 上,扩展您的命令的是 shell(不是调用的程序)和 通配.有关更多信息,请参阅此答案.当前工作目录的概念不同.

The way of interpreting commands is different (on Windows look also into PowerShell, which I don't know). On Unix it is the shell (not the invoked programs) that is expanding your command and globbing. See this answer for more. The notion of current working directory is different.

操作系统概念在 Windows 和 Unix 或 POSIX 上(略有或显着)不同.例如,文件目录进程是不同的(比如一个文件可以写由一个进程在 Unix 上被另一个进程删除,它可以通过 硬链接), .... 等等.... 你可以阅读操作系统:三个简单的部分概述.

the operating system concepts are (slightly or significantly) different on Windows and on Unix or POSIX. For example, files, directories, processes, libraries are different (for example, a file can be written by a process and removed by another one on Unix and it can have several names on Linux thru hard links), .... etc.... You could read Operating Systems: Three Easy Pieces for an overview.

Unix 哲学并不(总是)适用于 Windows.>

the Unix philosophy is not (always) applicable to Windows.

因此您需要学习 Unix(或 POSIX)并编写自己的 shell 脚本 从头开始​​.不要尝试翻译"bat 脚本 到 Unix shell 脚本,但重新设计它完全(从您希望它解决的问题开始).

So you need to study Unix (or POSIX) and write your own shell script from scratch. Don't try to "translate" a bat script to a Unix shell script, but redesign it entirely (starting from the problem you want it to solve).

(和 WineDosBox 对您的情况没有帮助)

(and Wine or DosBox is not helpful in your case)

另请阅读SCP 以及FTP.也许使用一些分布式版本控制系统,如git 可能与您相关(例如共享脚本、源代码等...).

Read also about SCP and perhaps FTP. Perhaps using some distributed version control system like git could be relevant for you (e.g. to share scripts, source code, etc...).

如果您需要远程远程 Windows机器(例如从Unix机器)上运行一些Windows .bat脚本,您应该使用一些远程命令运行服务(即,找到并使用一些等效的SSH 服务在 Windows 上,并在 Unix 上使用相应的客户端).请参阅.

If you need to run remotely some Windows .bat script on a distant Windows machine (e.g. from a Unix machine), you should use some remote command running service (that is, find and use some equivalent of SSH service on Windows, and use the corresponding client on Unix). See this.

因此,如果您需要在 Unix 机器上远程运行 Windows 服务器上的某些内容(例如某些程序、某些脚本、某些命令),您应该问一个不同的问题(或者至少对当前的问题进行很多改进).

阅读客户端-服务器模型以及应用层 以使用正确的术语.您应该命名您想要涉及的协议、服务器、客户端和服务.不使用它们就不会神奇地触发".

Read about the client-server model and about application layer to use the correct terminology. You should name what protocol, server, client, service you want to involve. Nothing is magically "triggered" without using them.

附注.我从 1987 年开始使用 Unix,从 1993 年开始使用 Linux.我从未使用过 Windows.

PS. I'm using Unix since 1987, Linux since 1993. I never used Windows.

这篇关于在 unix 中运行 .bat 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆