简体   繁体   English

在Python子进程中使用鞭尾

[英]Using whiptail with Python subprocess

I am executing the following whitetail command mentioned here WhipTail Example 我正在执行以下此处提到的白尾命令WhipTail示例

whiptail --title "Check list example" --checklist \
"Choose user's permissions" 20 78 4 \
"NET_OUTBOUND" "Allow connections to other hosts" ON \
"NET_INBOUND" "Allow connections from other hosts" OFF \
"LOCAL_MOUNT" "Allow mounting of local devices" OFF \
"REMOTE_MOUNT" "Allow mounting of remote devices" OFF

Python code: Python代码:

   cmd = ['whiptail', '--title', "Check list example", '--checklist', "Choose user's permissions", '20', '78', '4',
        " NET_OUTBOUND", " Allow connections to other hosts", "ON",
        " NET_INBOUND", " Allow connections from other hosts", "OFF",
        " LOCAL_MOUNT", " Allow mounting of local devices", "OFF"
        " REMOTE_MOUNT", " Allow mounting of remote devices", "OFF"]

   p = subprocess.Popen(cmd)
   p.communicate()

It does not work. 这是行不通的。 Could you please suggest where I am going wrong. 您能否建议我要去哪里错了。

Error Message. 错误信息。 The standard error message for whiptail. 鞭尾的标准错误消息。

Executing Command
Box options: 
    --msgbox <text> <height> <width>
    --yesno  <text> <height> <width>
    --infobox <text> <height> <width>
    --inputbox <text> <height> <width> [init] 
    --passwordbox <text> <height> <width> [init] 
    --textbox <file> <height> <width>
    --menu <text> <height> <width> <listheight> [tag item] ...
    --checklist <text> <height> <width> <listheight> [tag item status]...
    --radiolist <text> <height> <width> <listheight> [tag item status]...
    --gauge <text> <height> <width> <percent>
Options: (depend on box-option)
    --clear             clear screen on exit
    --defaultno         default no button
    --default-item <string>     set default string
    --fb, --fullbuttons     use full buttons
    --nocancel          no cancel button
    --yes-button <text>     set text of yes button
    --no-button <text>      set text of no button
    --ok-button <text>      set text of ok button
    --cancel-button <text>      set text of cancel button
    --noitem            don't display items
    --notags            don't display tags
    --separate-output       output one line at a time
    --output-fd <fd>        output to fd, not stdout
    --title <title>         display title
    --backtitle <backtitle>     display backtitle
    --scrolltext            force vertical scrollbars
    --topleft           put window in top-left corner
    -h, --help          print this message
    -v, --version           print version information 

You are missing comma at line: 您在以下行缺少逗号:

" LOCAL_MOUNT", " Allow mounting of local devices", "OFF",

And as @BrianCain noted shlex.split is your comrade when it comes to turning strings into list of arguments. 正如@BrianCain指出的那样 ,在将字符串转换为参数列表时, shlex.split是您的同志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM