V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
he110comex
V2EX  ›  问与答

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

  •  
  •   he110comex · Feb 1, 2021 · 4047 views
    This topic created in 1917 days ago, the information mentioned may be changed or developed.
    将下面的内容粘贴到文本编辑器里面,文件后缀改为 .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 replies    2021-02-01 11:54:53 +08:00
    zhanghua0
        1
    zhanghua0  
       Feb 1, 2021
    wine ?不过高版本系统强制 64 位程序,wine 用不了了
    A3m0n
        2
    A3m0n  
       Feb 1, 2021
    由于指令并不多,可以考虑用 Shell 重写一遍。
    Soar360
        3
    Soar360  
       Feb 1, 2021
    你这是图种吧?
    llllIIIIllll
        4
    llllIIIIllll  
       Feb 1, 2021
    显然, macos 没有 bat 文件的解释器,所以无法执行 bat 文件.
    如果你只是想要一个跨平台运行的脚本,方法有 2,
    1. 使用 powershell, macos 上安装 powershell for mac
    2. 使用 bash.
    如果你无法重写 bat 脚本.又确实需要在 macos 上运行 bat 文件, 则可以考虑安装 windows 虚拟机.
    ysc3839
        5
    ysc3839  
       Feb 1, 2021
    如果要一个通用的方法,可以考虑 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

    我没测试过,可能存在问题。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2338 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 61ms · UTC 15:38 · PVG 23:38 · LAX 08:38 · JFK 11:38
    ♥ Do have faith in what you're doing.