468,457 Members | 1,555 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,457 developers. It's quick & easy.

popen/system()

Hello,

I have beeen googling for hours and havent found the answer I am looking for so I have come to experts. I hope you can help!

FILE * snapshot;
char mystring [100];

snapshot = popen("screen -x svr00001", "r");
pclose(snapshot);
if (snapshot == NULL) {
perror ("Not running");
} else {
fgets (mystring , 100 , snapshot);
puts (mystring);
}

However, this "streams" the data that the "screen" command is running how do I get it to "print" out the last line being executed by the program?

Thanks in advance!
Jan 19 '08 #1
8 3182
Savage
1,764 Expert 1GB
Hello,

I have beeen googling for hours and havent found the answer I am looking for so I have come to experts. I hope you can help!

FILE * snapshot;
char mystring [100];

snapshot = popen("screen -x svr00001", "r");
pclose(snapshot);
if (snapshot == NULL) {
perror ("Not running");
} else {
fgets (mystring , 100 , snapshot);
puts (mystring);
}

However, this "streams" the data that the "screen" command is running how do I get it to "print" out the last line being executed by the program?

Thanks in advance!
Why do you close the stream immediately after opening it?
Jan 20 '08 #2
To try and get it to only get a bit of data rather than streaming the execution of "screen"
Jan 20 '08 #3
I just want to be able to return part of the screen command in a varialbe and not the whole screen execution.
Jan 20 '08 #4
*bump* is there any way of doing this?
Jan 21 '08 #5
rcronk
6
I don't know if it's valid to perform operations on something that has been closed. Have you tried closing it after you are done with it? If so, what happened?
Jan 21 '08 #6
There is no diffrence its the same result.
Jan 21 '08 #7
Is there another way of getting the information of a program running on "screen" on C.

I want to be able to get the last few lines of an console based applciation using C. Is this possible?
Jan 22 '08 #8
ppd
4
Hi,
I am not sure I understand what you mean, but I will say a few things anyway.

If it is a command line program outputting text to the screen or console, can you run this program from the command line
and tell it to write to a file? E.G.
command.exe > file
Then you would have the output in a file which you could
read with a C program.

If it is a screenshot or image of the entire console that you need, then you can get a screen shot using a command in windows (look in the windows help). It is some key+"Print Screen" that saves a copy of the entire screen of your computer into an image file. Then you are on your
own to deal with that.

good luck.
Jan 23 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Sami Viitanen | last post: by
2 posts views Thread by Your Friend | last post: by
3 posts views Thread by Grumble | last post: by
4 posts views Thread by agarwalpiyush | last post: by
3 posts views Thread by Jesse | last post: by
12 posts views Thread by Eric_Dexter | last post: by
reply views Thread by mcoliver | last post: by
25 posts views Thread by Jeremy Banks | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.