LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old 10-12-2007, 01:44 AM   #1
simopal6
Member
 
Registered: Jun 2006
Location: Italy
Distribution: Slackware 13.1
Posts: 230

Rep: Reputation: 30
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!
 
Old 10-12-2007, 10:45 AM   #2
juergen
Member
 
Registered: Sep 2001
Posts: 40

Rep: Reputation: 16
You could try expect or Pexpect. They are made for this kind of task.
 
Old 10-12-2007, 08:27 PM   #3
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044
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
 
Old 10-14-2007, 01:16 PM   #4
ray_80
Member
 
Registered: Oct 2007
Posts: 75

Rep: Reputation: 15
Quote:
Originally Posted by jlinkels View Post
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
 
Old 10-16-2007, 03:00 PM   #5
simopal6
Member
 
Registered: Jun 2006
Location: Italy
Distribution: Slackware 13.1
Posts: 230

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by jlinkels View Post
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!
 
Old 10-16-2007, 07:51 PM   #6
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044
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
 
Old 11-21-2014, 10:08 PM   #7
abencomoc90
LQ Newbie
 
Registered: Nov 2014
Posts: 1

Rep: Reputation: Disabled
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????
 
Old 11-22-2014, 05:54 AM   #8
simopal6
Member
 
Registered: Jun 2006
Location: Italy
Distribution: Slackware 13.1
Posts: 230

Original Poster
Rep: Reputation: 30
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
 
  


Reply


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
"/usr/bin/ls: reading directory .: Input/output error" DiZi Slackware 15 07-13-2008 10:03 AM
How to display "real time" view of process running in openSUSE 10.1 ramirez.alex SUSE / openSUSE 6 02-27-2007 03:48 AM
i got a problem: "REAL TIME CLOCK DRIVER v1.10e" ERROR Tyfn Linux - Software 1 02-01-2006 09:26 PM
"Real time" Apache log filtering with Perl skelly Programming 1 07-01-2004 02:24 PM
System freezing at "Real Time Clock Driver" raccoon Linux - Newbie 0 12-02-2003 02:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:05 AM.

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
Open Source Consulting | Domain Registration