Search code examples
pythonsubprocesspopenwhiptail

Using whiptail with Python subprocess


I am executing the following whitetail command mentioned here WhipTail Example

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:

   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 

Solution

  • 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.