V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
he110comex
V2EX  ›  问与答

如何在 macOS 系统运行 Windows 批处理指令?

  •  
  •   he110comex · 2021-02-01 08:51:28 +08:00 · 2799 次点击
    这是一个创建于 1172 天前的主题,其中的信息可能已经有所发展或是发生改变。
    将下面的内容粘贴到文本编辑器里面,文件后缀改为 .bat 即得到这个批处理文件,在 Windows 系统下可直接双击执行。

    效果:可将压缩文件打包到图片文件中,解压缩图片文件可得到原来的压缩文件。

    问题:
    如何在 macOS 系统运行这个 .bat 批处理文件?
    .
    .
    .

    附批处理指令
    (将下面的内容粘贴到文本编辑器里面,文件后缀改为 .bat 即得到这个批处理文件)
    -----------------------------------------
    echo off
    :loop
    cls
    echo 请拖入图像文件后回车:
    set /p imagefile=
    echo 请拖入 zip 文件后回车:
    set /p zipfile=


    copy /b %imagefile% + %zipfile% %zipfile%.jpg


    echo OK!已经将%zipfile%合并到%imagefile%。
    echo 合并后的文件为:%zipfile%.jpg


    ::del /f /s /q %imagefile%
    ::copy temp.jpg %imagefile:~0,-4%jpg
    ::del /f /s /q temp.jpg
    goto loop
    -----------------------------------------
    5 条回复    2021-02-01 11:54:53 +08:00
    zhanghua0
        1
    zhanghua0  
       2021-02-01 09:01:10 +08:00
    wine ?不过高版本系统强制 64 位程序,wine 用不了了
    A3m0n
        2
    A3m0n  
       2021-02-01 09:13:05 +08:00
    由于指令并不多,可以考虑用 Shell 重写一遍。
    Soar360
        3
    Soar360  
       2021-02-01 09:18:47 +08:00
    你这是图种吧?
    llllIIIIllll
        4
    llllIIIIllll  
       2021-02-01 10:54:34 +08:00
    显然, macos 没有 bat 文件的解释器,所以无法执行 bat 文件.
    如果你只是想要一个跨平台运行的脚本,方法有 2,
    1. 使用 powershell, macos 上安装 powershell for mac
    2. 使用 bash.
    如果你无法重写 bat 脚本.又确实需要在 macos 上运行 bat 文件, 则可以考虑安装 windows 虚拟机.
    ysc3839
        5
    ysc3839  
       2021-02-01 11:54:53 +08:00
    如果要一个通用的方法,可以考虑 Wine 或者虚拟机。

    如果只需要实现你问的这个,可以将以下代码保存为 .command 后缀的文件运行

    #!/bin/bash
    while :; do
    clear
    echo -n 请拖入图像文件后回车:
    read imagefile
    echo -n 请拖入 zip 文件后回车:
    read zipfile

    cat "$imagefile" "$zipfile" > "${zipfile}.jpg"

    echo OK!已经将 "$zipfile" 合并到 "$imagefile"
    echo 合并后的文件为: "${zipfile}.jpg"

    done

    我没测试过,可能存在问题。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1293 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 17:40 · PVG 01:40 · LAX 10:40 · JFK 13:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.