python - 将参数通过 .bat 文件传递​​给 .exe 文件,由 'PyInstaller' 转换

标签 python python-3.x batch-file ffmpeg pyinstaller

通过 .bat 文件向 PyInstaller 转换的 .exe 文件传递​​参数时出现错误
在我的 python 脚本中,我导入了以下库:

import time
from contextlib import closing
from PIL import Image
import subprocess
from audiotsm import phasevocoder
from audiotsm.io.wav import WavReader, WavWriter
from scipy.io import wavfile
import numpy as np
import re
import math
from shutil import copyfile, rmtree
import os
import argparse
from pytube import YouTube
import cv2
from datetime import datetime
import datetime
import os.path
import shutil
import webbrowser

这是我的 .bat 文件内容:
mode con: cols=100 lines=40
@echo off
COLOR 0A
title VideoCuts 
:LOOP
if "%~1"=="" goto :END
ShortCut.exe --input_file "%~1" --silent_threshold 0.1 --silent_speed 9999999.00 --frame_margin 5 --sample_rate 48000 --frame_quality 1 --output_file "%~n1_%date:~-10,2%%date:~-7,2%%date:~-4,4%_%time:~0,2%%time:~3,2%%time:~6,2%_videocuts.mp4"
pause

我还使用这个 .bat 文件进行了测试:
ShortCut.exe --input_file="%~1" --silent_threshold=0.1 --silent_speed=9999999.00 --frame_margin=5 --sample_rate=48000 --frame_quality=1 --output_file="videocuts.mp4"

this is my error message images during processing

最佳答案

创建 minimal reproducible example 时更容易回答问题的问题。

在 bat 脚本中执行命令的回显。例如,在你的 bat 文件中,在执行 ShortCut.exe 之前再写一行。
echo "ShortCut.exe --input_file="%~1" --silent_threshold=0.1 --silent_speed=9999999.00 --frame_margin=5 --sample_rate=48000 --frame_quality=1 --output_file="videocuts.mp4""
如果使用正确的参数调用可执行文件,这将为您提供信息。
根据您在 py 文件中的实现方式,可能会出现查找此输入文件和 echo 的问题。在运行命令之前执行它可能是解决它的完美方法。

作为pyinstaller文档提到,您还可以编写可执行文件何时卡住(Exe 形式)以及何时从 IDE 运行的条件

import sys
if getattr( sys, 'frozen', False ) :
    # running in a exe form
else :
    # running on your IDE (eg. Pycharm)

关于python - 将参数通过 .bat 文件传递​​给 .exe 文件,由 'PyInstaller' 转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59008259/

相关文章:

Python - 有没有办法自动化这个? <code>itertools.product</code>

python - 如何解决 "virtualenv: error: the following arguments are required: dest"错误?

python - 添加的 QMenu 未触发 QAction

Windows 批处理文件 - 如果窗口标题包含文本,则 taskkill

windows - 在windows命令行中自己计算

windows - 批处理脚本或 PowerShell 脚本从文本文件读取多个值并将其插入变量

Python 元组到字典,带有额外的键列表

python - 停止 Twisted 吞下异常

Python3 检查 Unicode 字符是否不存在

python - Tkinter.pack() 方法不显示 GUI