小编mut*_*mar的帖子

从 shell 返回值到 Python 脚本

我试图从 shell 脚本返回一个字符串到 python 得到以下错误。

./whiptail.sh: 10: return: Illegal number: uuiiu
Run Code Online (Sandbox Code Playgroud)

我尝试在 python 中直接使用 subprocess.Popen 运行whiptail命令,即使那时我无法从 python 读取用户输入..如果有人尝试过这个,请告诉我如何解决这个问题。

外壳脚本片段

#!/bin/sh


COLOR=$(whiptail --inputbox "What is your favorite Color?" 8 78 Blue --title "Example Dialog" 3>&1 1>&2 2>&3)
                                                                        # A trick to swap stdout and stderr.
# Again, you can pack this inside if, but it seems really long for some 80-col terminal users.
exitstatus=$?
if [ $exitstatus = 0 ]; then
    echo "User selected Ok and entered " $COLOR
    return $COLOR …
Run Code Online (Sandbox Code Playgroud)

python command-line bash scripts

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

bash ×1

command-line ×1

python ×1

scripts ×1