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?
Printable View
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.
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
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"
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 :/
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?
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.
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 :/
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.
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