bash - 批处理文件无法成功运行 bash 并打开 .sh 文件
问题描述
我正在尝试在 Windows 10 计算机上运行由 PyInstaller 创建的可执行文件。由于我的工作计算机上的某些安全性,我无法使用任何 Windows 终端 (TgApi) 运行 exe,但任何 bash 终端都可以出于我不理解的原因工作。为了解决这个问题,我正在尝试创建一个批处理文件,该文件将使用 bash 运行 exe。
这是 .bat 文件:
title Batch File
bash -x Shell_File.sh
pause
这是 .sh 文件:
#!/usr/bin/bash
chmod +x Executable.exe
bash ./Executable.exe
我不断收到的错误是Executable.exe: Executable.exe: cannot execute binary file
.
解决方案
我找到的解决方案如下所示。
这是 .bat 文件:
REM Get the current directory and set it to CURRENT_DIR
for /f "tokens=* delims=/" %%A in ('cd') do set CURRENT_DIR=%%A
REM Set variables to forward to Bash Shell
SET SHELLDIR=%CURRENT_DIR%
SET SHELL=%SHELLDIR%/bash.exe
SET BASH=%SHELL%
SET PATH=%SHELLDIR%;%PATH%
REM Pass variables and shell command file to Bash Shell
"%SHELL%" %* shell_commands.sh
这是 shell_commands.sh 文件:
cd (directory with executable)
./Executable.exe
推荐阅读
- apache-kafka-streams - 为什么 Kafka Streams 对 GlobalKTable 状态存储强制禁用日志记录?
- javascript - 如何将选择选项显示为按钮?
- vuejs2 - 具有 4 个空格标识的 Vue-CLI
- javascript - Firestore .startAt 无法正常工作
- scala - Circe Scala - 编码和解码 Map[] 和案例类
- c# - 如何使用回调函数跳出一个方法?
- sql-server - 在 openrowset 中使用存储过程会引发 login_mapping 错误
- android - 如果项目已在屏幕上显示设定的时间,则需要更新回收站视图中的项目
- vue.js - 使用 vue-test-utils 配置过滤器
- python - 如何从不同的模块访问树视图内容?