Redirecting stdout output to whiptail menu box


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Redirecting stdout output to whiptail menu box
# 1  
Old 08-11-2018
Redirecting stdout output to whiptail menu box

As a result of whiptail menu option I am getting a data from a file.

Naturally it is output to terminal as stdour.



I like to redirect the output back to the menu.

It can be done with single input of line of text , see attached.


I just cannot see where or how the sample attached

"swaps the stdout and stderr."









Quote:
A way to get free-form input from the user is via an input box. This displays a dialog with two buttons labelled Ok and Cancel.
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 else echo "User selected Cancel." fi echo "(Exit status was $exitstatus)"

Addendum

I am not sure what happen with the quite , it was part text part code Here it is agan as code



Code:

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 else     echo "User selected Cancel." fi  echo "(Exit status was $exitstatus)"

------ Post updated at 10:32 PM ------

I found answer here

BASH Programming - Introduction HOW-TO: All about redirection

------ Post updated 08-11-18 at 12:30 PM ------

OK, I jumped the gun.

I do understand the principle of redirecting , read "the book".

Unfortunately the book numbers the descriptors 0 thru 2 and the code I am using goes 1 thru 3 .

So which way is up ?



Or can I just use names such as "stdout" instead?



Code:
#file descriptors 0, 1 and 2 also known as 
 204 # 0 standard input (stdin), 
 205 # 1 standard output (stdout) 
 206 # 2 and standard error (stderr). 
 207 #or ? 
 208 # 1 stdin 
 209 # 2 stdout 
 210 # 3 error 
 211 foobar=$(whiptail --inputbox "REDIRECT TEST Enter some text" 10 30\
 212  3>&1 1>&2 2>&3)
 213 # error to input  
 214 # input to output 
 215 # output to error


Last edited by annacreek; 08-10-2018 at 11:24 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing positioning array as whiptail -- menu option

I may have asked this before, so forgive OF. Problem: I can pass positioning array as -- menu option to whiptail, but it does not show in the whiptail form as an array - only single (first member "lsusb" ) entry / line shows up. Code: DynamicEntry=$(whiptail \ --title "DEBUG... (1 Reply)
Discussion started by: annacreek
1 Replies

2. Shell Programming and Scripting

Bash Script - Whiptail Menu Help!

Hello, Been trying to build a menu with whiptail lately. However, my code doesn't seems to be working even though when i compared to other similar code they looks the same. #!/bin/bash clear whiptail --msgbox "Entering networking sub-menu" 20 78 whiptail --title Networking --menu... (8 Replies)
Discussion started by: malfolozy
8 Replies

3. Shell Programming and Scripting

Whiptail menu, getting back the variable

Hi all Only learning so if any mistakes, let me know I am trying to create a menu box with Whiptail, taking in the variables from a txt.file called Name.txt which has just 4 names listed for now, one below each other..ie Dave John Mike Mary Bash script is below and calls the txt... (8 Replies)
Discussion started by: olearydc
8 Replies

4. Shell Programming and Scripting

File descriptors, redirecting output, and stdout

Hello all. I've been lurking here for a year or two and finally decided to post. I need some assistance with file descriptors, stdout, and redirecting output. I've searched through a number of very helpful threads here (unfortunately I can't link to any of them yet due to my low post count...),... (2 Replies)
Discussion started by: Michael_K
2 Replies

5. Shell Programming and Scripting

Redirecting stdout continously to a file

I have a C program that continously outputs info to stdout. The problem is that I am redirecting the stdout and stderr to a file and stdout is written at the end of the problem rather than continously to the file. This could be a problem if for example the program is killed and the stdout output is... (3 Replies)
Discussion started by: igurov
3 Replies

6. Shell Programming and Scripting

Redirecting stdout problem

I have a simple bash script that prints sth every 5 seconds. What I do is the following. I redirect the output of the script to a file, tail the file and see that it works and then from another console I delete the file where the output is redirected to. Even though I have deleted the file, the... (2 Replies)
Discussion started by: igurov
2 Replies

7. Shell Programming and Scripting

redirecting to stdout in betwen command

can anyone help me in making singleline command for Capital Letters are folders ,small letter are files X,Y,Z are subfolders of A as shown below A - X,Y,Z Folder X has three files a.txt,b.txt,c.txt similarly Y,Z. as shown below X- a.txt,b.txt,c.txt Y- a.txt,b.txt,c.txt Z-... (4 Replies)
Discussion started by: phoenix_nebula
4 Replies

8. Shell Programming and Scripting

Preserve output order when redirecting stdout and stderr

Hi, I already searched through the forum and tried to find a answer for my problem but I didn't found a full working solution, thats way I start this new thread and hope, some can help out. I wonder that I'm not able to find a working solution for the following scenario: Working in bash I... (8 Replies)
Discussion started by: Boemm
8 Replies

9. UNIX for Dummies Questions & Answers

Redirecting several outputs to /dev/stdout

I have an executable that, depending on its input, outputs to either one file or several. It usually prints nothing on screen. The usual way to call this program is to specify an input and output filenames, like this: ./executable.exe -i inputfile -o outputfileIt will then try to use the output... (1 Reply)
Discussion started by: aplaydoc
1 Replies

10. Shell Programming and Scripting

Redirecting part of output to stdout

Hi, I am trying to execute a command like this: find ./ -name "*.gz" -exec sh -c 'zcat {} | awk -f parse.awk' \; >> output If I want to print the filename, i generally use the -print argument to the find command but when I am redirecting the output to a file, how can I print just the... (2 Replies)
Discussion started by: Legend986
2 Replies
Login or Register to Ask a Question