Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
10-12-2007, 01:44 AM
|
#1
|
Member
Registered: Jun 2006
Location: Italy
Distribution: Slackware 13.1
Posts: 230
Rep:
|
Reading an application's output in "real time"
Hello!
Suppose i have an application (in my case, wpa_supplicant), which, when executed, prints some output but never exits. Can i read the application's output as soon as it is printed?
I'm writing a shell script to manage wireless connections, and i need to use wpa_supplicant.. The problem is that wpa_supplicant never exits, so i don't know when authentication has been completed.
Any help?
Thank you!
|
|
|
10-12-2007, 10:45 AM
|
#2
|
Member
Registered: Sep 2001
Posts: 40
Rep:
|
You could try expect or Pexpect. They are made for this kind of task.
|
|
|
10-12-2007, 08:27 PM
|
#3
|
LQ Guru
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
|
If you can redirect the output of wpa-supplicant to a file, or you pipe the output into the logger program within your script, do so. In another process you do a tail -f <filename> and presto.
jlinkels
|
|
|
10-14-2007, 01:16 PM
|
#4
|
Member
Registered: Oct 2007
Posts: 75
Rep:
|
Quote:
Originally Posted by jlinkels
If you can redirect the output of wpa-supplicant to a file, or you pipe the output into the logger program within your script, do so. In another process you do a tail -f <filename> and presto.
jlinkels
|
Good advice. Have you also tried strace?
man strace
Regards
|
|
|
10-16-2007, 03:00 PM
|
#5
|
Member
Registered: Jun 2006
Location: Italy
Distribution: Slackware 13.1
Posts: 230
Original Poster
Rep:
|
Quote:
Originally Posted by jlinkels
If you can redirect the output of wpa-supplicant to a file, or you pipe the output into the logger program within your script, do so. In another process you do a tail -f <filename> and presto.
jlinkels
|
I've tried redirecting the output, and using cat to read it. The problem is that the output isn't flushed to file until the program exists. How can i force flushing?
Thanks!
|
|
|
10-16-2007, 07:51 PM
|
#6
|
LQ Guru
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
|
Do you mean that wpa-supplicant doesn't write anything before the program exists? If so, there is nothing to do about it.
However, if wpa-supplicant writes any output, you can pipe it into logger. If wpa-supplicant write the interesting stuff to stderr, you can redirect stderr to stdout: 2>&1
Like:
Code:
$wpa-supplicant -options 2>&1 | logger
jlinkels
|
|
|
11-21-2014, 10:08 PM
|
#7
|
LQ Newbie
Registered: Nov 2014
Posts: 1
Rep:
|
Same problem
I got the same problem.... wpa_supplicant show log messages on the shell screen when you run it interactively, but their output were redirected don't flush the messages until end the process. I don't find a way to send the log messages to a file in realtime in order to do some script with those log messages... Any idea????
|
|
|
11-22-2014, 05:54 AM
|
#8
|
Member
Registered: Jun 2006
Location: Italy
Distribution: Slackware 13.1
Posts: 230
Original Poster
Rep:
|
I had completely forgotten about the existence of this thread...
Anyway, you should probably follow jlinkels' advice, pipe wpa_supplicant's output to some program which reads from stdin. I have no idea if I did follow his suggestion at the time.
The first thing that comes to mind is calling the application like this:
Code:
$ wpa_supplicant -options | logger
where logger is a script which, for example processes its input (i.e., wpa_supplicant's output) line by line:
Code:
#!/bin/bash
while read line ; do
...process $line, e.g. grep, sed, tr, cut, whatever
done
Last edited by simopal6; 11-22-2014 at 05:55 AM.
Reason: Bad usage of CODE
|
|
|
All times are GMT -5. The time now is 10:05 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|