LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-09-2018, 10:09 AM   #1
Jim232
Member
 
Registered: Apr 2018
Posts: 53

Rep: Reputation: Disabled
bash - Processing interactive output from whiptail


Again, the OF has an issue with using whiptail "menu".

I am trying to process "wpa_cli" - network setup / configuration etc.
It has an "interactive " mode and when used without any options it puts out ( periodically ) a nice response / output.

Here is the real McCoy:

Code:
pi@pi:/media/pi/WORK $ wpa_cli
wpa_cli v2.4
Copyright (c) 2004-2015, Jouni Malinen <j@w1.fi> and contributors

This software may be distributed under the terms of the BSD license.
See README for more details.


Selected interface 'p2p-dev-wlan1'

Interactive mode

<3>CTRL-EVENT-SCAN-RESULTS 
<3>CTRL-EVENT-SCAN-RESULTS 
<3>CTRL-EVENT-SCAN-RESULTS 
<3>CTRL-EVENT-SCAN-RESULTS 
<3>CTRL-EVENT-SCAN-RESULTS 
<3>CTRL-EVENT-SCAN-RESULTS 
<3>CTRL-EVENT-SCAN-RESULTS 
<3>CTRL-EVENT-SCAN-RESULTS
Now I am after adding this (default) command into whiptail menu and when executed I get this output:

Code:
Copyright (c) 2004-2015, Jouni Malinen <j@w1.fi> and contributors
│
│ This software may be distributed under the terms of the BSD license.
│ See README for more details.
│
│
│ Selected interface 'p2p-dev-wlan1'
│
│ Interactive mode
│
│ > > ^M^[[K
Please note MISSING / corrupted etc interactive responses.

I believe part of the problem is not using correct redirection.
Here is the scrip which actually outputs the whiptail to the "screen".

Apparently I need something else (while loop ?) to periodically capture / output interactively from whiptail.

I am not sure how or if it is even possible.

Code:
whiptail \
--title "TEST Command * $choice *  output $LINENO" \
--separate-output \
--scrolltext  \
--msgbox "$($choice  2>&1)"   $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \
 2>&1 #note redirect $choice 2>&1

Last edited by Jim232; 10-09-2018 at 03:37 PM. Reason: Now the solution will be forthcomin....
 
Old 10-09-2018, 11:17 AM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: FreeBSD/Slackware-14.2+/ArcoLinux
Posts: 9,173

Rep: Reputation: 1952Reputation: 1952Reputation: 1952Reputation: 1952Reputation: 1952Reputation: 1952Reputation: 1952Reputation: 1952Reputation: 1952Reputation: 1952Reputation: 1952
you also really need to learn how to use the code tags in here, you seem to be coming along with your programming, so I am not seeing why you cannot figure out how to type [ code ] [ /code ] in a text box. or using the button in the 'go advance' selection of this forum. Please correct that error in your postings.

though this page shows how to create a interactive shell using whiptail

http://xmodulo.com/create-dialog-box...ll-script.html

you might need to take a few steps backwards and learn how to use if statements and work off the returns withing the conditions test, there is an example of this in that post. it does not seem to hard,
Code:
#!/bin/bash

DISTROS=$(whiptail --title "Test Checklist Dialog" --radiolist \
"What is the Linux distro of your choice?" 15 60 4 \
"debian" "Venerable Debian" ON \
"ubuntu" "Popular Ubuntu" OFF \
"scoobie do" "Stable CentOS" OFF \
"mint" "Rising Star Mint" OFF 3>&1 1>&2 2>&3)
 
exitstatus=$?
if [ $exitstatus = 0 ]; then
    echo "The chosen distro is:" $DISTROS
else
    echo "You chose Cancel."
fi

I HEAVILY AND STRONGLY argue that you use code tags and post your code, and results in separate boxes so we can easily read it easier, otherwise this just saying I did "something" and this is what I got, then blatantly post something, then ask "how do I do something with that?"

Without showing what you are talking about is wasting mine, and others, along with your time in getting some kind of workable answer(s) to help you along in your endeavor.

I cannot make heads or tail of what you posted.

Last edited by BW-userx; 10-09-2018 at 11:33 AM.
 
1 members found this post helpful.
Old 10-09-2018, 11:44 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 19,048

Rep: Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893
It isn't possible. You can not use wpa_cli in interactive and be able to send it commands via whiptail.
 
1 members found this post helpful.
Old 10-09-2018, 11:46 AM   #4
Jim232
Member
 
Registered: Apr 2018
Posts: 53

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by BW-userx View Post
you also really need to learn how to use the code tags in here, you seem to be coming along with your programming, so I am not seeing why you cannot figure out how to type [ code ] [ /code ] in a text box. or using the button in the 'go advance' selection of this forum. Please correct that error in your postings.

though this page shows how to create a interactive shell using whiptail

http://xmodulo.com/create-dialog-box...ll-script.html

you might need to take a few steps backwards and learn how to use if statements and work off the returns withing the conditions test, there is an example of this in that post. it does not seem to hard,
Code:
#!/bin/bash

DISTROS=$(whiptail --title "Test Checklist Dialog" --radiolist \
"What is the Linux distro of your choice?" 15 60 4 \
"debian" "Venerable Debian" ON \
"ubuntu" "Popular Ubuntu" OFF \
"scoobie do" "Stable CentOS" OFF \
"mint" "Rising Star Mint" OFF 3>&1 1>&2 2>&3)
 
exitstatus=$?
if [ $exitstatus = 0 ]; then
    echo "The chosen distro is:" $DISTROS
else
    echo "You chose Cancel."
fi

I HEAVILY AND STRONGLY argue that you use code tags and post your code, and results in separate boxes so we can easily read it easier, otherwise this just saying I did "something" and this is what I got, then blatantly post something, then ask "how do I do something with that?"

Without showing what you are talking about is wasting mine, and others, along with your time in getting some kind of workable answer(s) to help you along in your endeavor.

I cannot make heads or tail of what you posted.

Thanks, but no thanks.
It really serves no purpose to answer with telling me how to tag code and than saying

"I cannot make heads or tail of what you posted."

It is illogical to discuss something if you have have no understating what it is about. And it no shame to just ignore the post. Somebody else will pick up the ball and run with it.

Next time do not waste your precious time saying nothing.

BTW That is not what I asked, but since you said I cannot make heads or tail of what you posted" it is irrelevant for both of us to discuss.
Have a great day.
 
Old 10-09-2018, 11:59 AM   #5
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: FreeBSD/Slackware-14.2+/ArcoLinux
Posts: 9,173

Rep: Reputation: 1952Reputation: 1952Reputation: 1952Reputation: 1952Reputation: 1952Reputation: 1952Reputation: 1952Reputation: 1952Reputation: 1952Reputation: 1952Reputation: 1952
Quote:
Originally Posted by Jim232 View Post
Thanks, but no thanks.
It really serves no purpose to answer with telling me how to tag code and than saying

"I cannot make heads or tail of what you posted."

It is illogical to discuss something if you have have no understating what it is about. And it no shame to just ignore the post. Somebody else will pick up the ball and run with it.

Next time do not waste your precious time saying nothing.

BTW That is not what I asked, but since you said I cannot make heads or tail of what you posted" it is irrelevant for both of us to discuss.
Have a great day.
you have no understanding of my abilities to pick up on what you're trying to do and perhaps even figure it out before you, and YES code tag are important, along with your post makes no real sense.


as all of this code of yours , what this code tags

Code:
I believe part of the problem is not using correct redirection.
Here is the scrip which actually outputs the whiptail to the "screen".

Apparently I need something else (while loop ?) to periodically capture / output interactively from whiptail.

I am not sure how or if it is even possible.

whiptail \
--title "TEST Command * $choice * output $LINENO" \
--separate-output \
--scrolltext \
--msgbox "$($choice 2>&1)" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \
2>&1 #note redirect $choice 2>&1
prints out this
Code:
$ whiptail \
> --title "TEST Command * $choice * output $LINENO" \
> --separate-output \
> --scrolltext \
> --msgbox "$($choice 2>&1)" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \
> 2>&1 #note redirect $choice 2>&1
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
which has nothing to do with wpa_cli

it just shows the abilities of whiptail boxes. cannot make heads or tails out of what your whiptail code that this is not, it has nothing to do with selections for wpa_cli that is for sure.

and just because you cannot wrap your head around common practices and procedures for LQ Forum tells me a lot about you.

if you are trying to use wpa_cli within a external feature by calling to it, then you are going to have to learn how to trap its out put then put that to use if that is even possible.

Last edited by BW-userx; 10-09-2018 at 12:06 PM.
 
1 members found this post helpful.
Old 10-09-2018, 12:46 PM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 8,064
Blog Entries: 13

Rep: Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505
Why would you not use a whiptail -infobox which does not require user intervention?

Wiki on Whiptail/Infobox
Quote:
A simple type of dialog box in Whiptail is the info box. This shows a dialog box containing text to the user.
And from the -messagebox information:
Quote:
A message box is very similar to an info box, except that it waits for the user to hit the OK button. Usage is similar to the info box.
I've never used these, so I'm unsure how long an infobox stays up. Meanwhile if you have no user interaction, as in someone to hit OK, then I'd try the infobox. Unsure if the rest of your syntax is correct. Perhaps just use the --title and --infobox directives and leave out the --separate-output and --scrolltext for now. I'd also keep the --infobox term more simple and just put in the quoted section along with the height and width and not try any further I/O re-directs until you've debugged it enough.
 
Old 10-09-2018, 01:45 PM   #7
Jim232
Member
 
Registered: Apr 2018
Posts: 53

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
Why would you not use a whiptail -infobox which does not require user intervention?

Wiki on Whiptail/InfoboxAnd from the -messagebox information:I've never used these, so I'm unsure how long an infobox stays up. Meanwhile if you have no user interaction, as in someone to hit OK, then I'd try the infobox. Unsure if the rest of your syntax is correct. Perhaps just use the --title and --infobox directives and leave out the --separate-output and --scrolltext for now. I'd also keep the --infobox term more simple and just put in the quoted section along with the height and width and not try any further I/O re-directs until you've debugged it enough.
I have no need to "minimize" the options, the script is working as expected.
I cannot use infobox because wpa_cli is in two way "interactive " mode.
There is "output" coming from wpa_cli and I can also input "commands" to modify the wpa_cli.

I am looking into adding "read" AFTER the whiptail is finished.
I still have a problem with redirection - cannot make plain "read" to actually work.
 
Old 10-09-2018, 01:56 PM   #8
rtmistler
Moderator
 
Registered: Mar 2011
Location: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 8,064
Blog Entries: 13

Rep: Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505
I may be interpreting your intentions and problem incorrectly then.

From what I gather, you wish to use whiptail to output the "<3>CTRL-EVENT-SCAN-RESULTS" information to dialog windows. Is this correct or incorrect?
 
Old 10-09-2018, 02:42 PM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 19,048

Rep: Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893
It would be much easier IMHO to use wpa_cli using via its command line options then interactive mode and display the desired information in a dialog box.
 
Old 10-09-2018, 03:28 PM   #10
Jim232
Member
 
Registered: Apr 2018
Posts: 53

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
It would be much easier IMHO to use wpa_cli using via its command line options then interactive mode and display the desired information in a dialog box.
Yes, but since the intent is to troubleshoot WiFi interactive mode seems better. I suppose I could build my own "loop" - right now I can cascade commands in "single file", adding "loop" would solve some issues, easy.
 
Old 10-09-2018, 03:33 PM   #11
Jim232
Member
 
Registered: Apr 2018
Posts: 53

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
I may be interpreting your intentions and problem incorrectly then.

From what I gather, you wish to use whiptail to output the "<3>CTRL-EVENT-SCAN-RESULTS" information to dialog windows. Is this correct or incorrect?
Yes, part of it.
From my initial post you could see that I cannot even print a single line / response.
That tells me that whiptail does not like these <> and others characters.
Perhaps I need to redesign the whole mess not to use whiptail in wpa_cli.
 
Old 10-09-2018, 04:08 PM   #12
michaelk
Moderator
 
Registered: Aug 2002
Posts: 19,048

Rep: Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893
Anything you can do interactive you should be able to do via command line options except for unsolicited messages i.e event messages, user‐name/password requests.

Last edited by michaelk; 10-09-2018 at 04:16 PM.
 
Old 10-09-2018, 05:56 PM   #13
rtmistler
Moderator
 
Registered: Mar 2011
Location: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 8,064
Blog Entries: 13

Rep: Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505Reputation: 3505
Quote:
Originally Posted by Jim232 View Post
Yes, part of it.
From my initial post you could see that I cannot even print a single line / response.
That tells me that whiptail does not like these <> and others characters.
Perhaps I need to redesign the whole mess not to use whiptail in wpa_cli.
Whiptail will post a dialog. That's what it does. If you just want to print, the I/O redirects you are using are fine.
 
Old 10-10-2018, 09:21 AM   #14
Jim232
Member
 
Registered: Apr 2018
Posts: 53

Original Poster
Rep: Reputation: Disabled
INCORRECT USAGE OF WHIPTAIL - CANNOT BE SOLVED Just FYI

I am posting this snippet just in case somebody has an idea HOW TO FIX IT USING SOME HACK IN whiptail.


I changed "wpa_cli" to "strace wpa_cli".

When used as a command in terminal I get all correct output, no problem whatsoever.
The wpa-cli interactive mode works great.

When I use "strace wpa_cli" as whiptail menu it fails right after "interactive mode" text is output. No scan outputs, but the "strace" still puts out data, and then it terminates.

My conclusion as suspected from this discussion- whiptail "menu" is not getting data from "wpa_cli". And cannot react to input.

Simple as that - it is not designed to work "interactively".
CASE CLOSED



Code:
Selected interface '\''p2p-dev-wlan0'\''

Interactive mode IN TERMINAL - WORKS 
)    = 18
write(1, "\n", 1
)                       = 1
clock_gettime(CLOCK_BOOTTIME, {tv_sec=494, tv_nsec=905520769}) = 0
clock_gettime(CLOCK_BOOTTIME, {tv_sec=494, tv_nsec=905700195}) = 0
_newselect(1, [], [], [], {tv_sec=0, tv_usec=0}) = 0 (Timeout)


Interactive mode IN WHIPTAIL MENU FAILS 

> ) = 236
clock_gettime(CLOCK_BOOTTIME, {tv_sec=1102, tv_nsec=321582437}) = 0
clock_gettime(CLOCK_BOOTTIME, {tv_sec=1102, tv_nsec=321713844}) = 0
_newselect(5, [0 4], [], [], {tv_sec=4, tv_usec=9
 
  


Reply

Tags
bash


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
whiptail bash command poor man GUI interface Jim232 Linux - Newbie 31 10-09-2018 12:28 AM
Help with bash/whiptail script capthookb Programming 12 01-06-2016 06:25 AM
[SOLVED] Bash Script - Reading User Input while Processing output from Command within Bash cleeky Linux - General 5 05-27-2014 02:57 PM
[SOLVED] Need a BASH for loop for processing many files and naming the output files Jeff9 Linux - Newbie 13 05-02-2014 12:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration