Hello,
I use fp = popen("/bin/bash -c command" , "r") to read the output of the command.
The problem is that i don't take the whole output, i take only the output that an unmaximize shell window shows. Is it possible to take the whole text?
Hello,
I use fp = popen("/bin/bash -c command" , "r") to read the output of the command.
The problem is that i don't take the whole output, i take only the output that an unmaximize shell window shows. Is it possible to take the whole text?
Of course. #1) what's the command. #2) post the code you are using to read from it.
Be aware some command output is to stderr, not stdout, and popen only reads from stdout. However, you can redirect by appending "2>&1" to the command.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
My guessing muscles are a little rusty, but I would guess that means that you are using fgets to read into an 80-character buffer, meaning you will only get 80 characters at a time (although notice that subsequent reads should get you the rest of the line). If you want longer lines, make the lines bigger (heck, go crazy, use BUFSIZ).
i use this :
fp2 = popen("/bin/bash -c 'airodump-ng mon0 2>&1' ", "r");
setvbuf ( fp2, NULL, _IOLBF, NULL);
i read with this :
fgets(path, PATH_MAX, fp2);
and i get this
CH 1 ][ Elapsed: 8 s ][ 2010-05-02 00:56
BSSID PWR Beacons #Data, #/s CH MB ENC CIPHER AUTH ESSID
00:1F:9F:CF:F5:A3 -48 10 0 0 1 54 WPA2 CCMP PSK Thoms
BSSID STATION PWR Rate Lost Packets Probes
instead of this
CH 8 ][ Elapsed: 0 s ][ 2010-05-02 00:59
BSSID PWR Beacons #Data, #/s CH MB ENC CIPHER AUTH ESSID
00:1F:9F:CF:F5:A3 -46 6 0 0 1 54 WPA2 CCMP PSK Thomson679897
BSSID STATION PWR Rate Lost Packets Probes
Hmm. It could be that this app detects the terminal size to decide how to format the output, and uses an 80 char default. That's sort of a design flaw, you should check to see there are no command line switches to control this.
What happens if you redirect the output to a file while in an unmaximized terminal?
airodump-ng mon0 > tmp.txt
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
same thing. if the terminal is unmaximized i only get thom :/ how can i fix it? i want the whole output
Well, so it is the app itself then. There may be nothing you can do about it, like I said this would be a design flaw/oversight. Unless there is a switch in the documentation...
There is a bash environment, COLUMNS, which changes when you resize the terminal. Hopefully, your app uses that.
With the terminal unmaximized, type:
[prompt] echo $COLUMNS
The answer is probably 80. Now try to spoof the value:
[prompt] COLUMNS=50
No spaces around the equals sign! Now execute your command. If it prints out only fifty chars wide, that's your ticket (also try settting it to 120, output to a file, and check that).
I can't say for sure that you can set an env variable for popen because I've never tried, but if that works, try using setenv() to set COLUMNS before the popen() call. You could also use "COLUMNS=120 && airodump-ng mon0"
Last edited by MK27; 05-01-2010 at 04:30 PM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Noep, nothing changed :/ maybe the problem is at the buffer?
i change the columns to 50. I use echo $COLUMNS it returns 50. I run the airodump-ng mon0 > tmp.txt and the columns change to 80 :/
Last edited by TuXaKoS; 05-01-2010 at 04:35 PM.
Yeah, it doesn't affect the shell's own internal commands either. It's just the only applicable one I could find.
Are you sure there is no option to the command at all for formatting? Do you have the source code?
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Wow. Well, you could try poking around the source to find out how it does this. It should be there somewhere. Seeing as how the default is 80, you could try searching for that number, methinks they do set it since using popen does not involve a terminal, it is not bash which provides that number.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
hm.. i don't think that COLUMNS is the problem. :/ i use setenv to change it to 125. I use getenv before and after popen and it's still 125 but the output is only 80. :/
i creater a buffer, char *testbuffer[BUFSIZ]
and i used
setvbuf ( fp2, testbuffer, _IOLBF, BUFSIZ);
but nothing changed :/
Last edited by TuXaKoS; 05-01-2010 at 05:29 PM.
Yeah, COLUMNS may only be used by bash to format select() output.
Looks like there are a few ways of doing this in C tho. Check the source to see if they include <termcap.h> or <sys/ioctl.h>. ioctl things are all set/got with the ioctl() C function. There's tons of them, but they are mostly undocumented.
Have a look here:
Getting terminal width in C? - Stack Overflow
Notice they are using various pre-defined structures and bitflags such as "winsize" and TIOCGWINSZ. These will be undocumented too, but since you are only looking to see if they are used, that is not such a big deal.
If you can dig around in the source and figure out how this decision is being made, you're most of the way to a solution. Sort of tedious, but you may learn some stuff. ioctl() is a nifty thing to know about, as the name implies it's kind of a catch-all for dealing with various system I/O protocols.
Last edited by MK27; 05-01-2010 at 05:38 PM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Did you try calling airodump directly instead of calling it through bash? What is the reason for this by the way?
Also, so I'm assuming this is for wireless cracking ?
EDIT: Also if you just run ENVVAR="blah" alone by itself it just sets that variable to "blah" then promptly discards it and restores its original value. The correct way would be to either "export ENVVAR=blah" or to include it on the call to airodump on the command line:
Code:me@box$ ENVVAR=blah airodump-ng whatever 2>&1
Last edited by nonpuz; 05-01-2010 at 05:45 PM.