473,233 Members | 1,543 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,233 software developers and data experts.

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 3511
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

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

Similar topics

2
by: Sami Viitanen | last post by:
Hello, I was using os.popen function to get CVS command output to string from script.. Same commands worked well with Windows, but Linux seems to have problem with those. Whole CVS commands...
2
by: Your Friend | last post by:
Hello All, I'm relatively new to Python programming but have been working on this problem for a little bit now ... I initially began writing UNIX scripts in Python and thought it was the...
3
by: Grumble | last post by:
Hello all, Is there an iostream equivalent to cstdio's popen()? Is there a way to change a FILE * into an iostream?
4
by: agarwalpiyush | last post by:
Hello, I am going nuts with trying to get the following to work: This is what I intend to do: I have a line in /etc/syslog.conf which I need to delete based on ip-address provided to me in a...
5
by: nic | last post by:
On my system (WinXP) typing the following line into command prompt(cmd.exe) successfully scans the file test1.txt: "c:\Program Files\Grisoft\AVG Free\avgscan.exe" "c:\program...
3
by: Jesse | last post by:
Hi all, I have a problem using wget and Popen. I hope someone can help. -- Problem -- I want to use the command: wget -nv -O "dir/cpan.txt" "http://search.cpan.org" and capture all it's...
12
by: Eric_Dexter | last post by:
I am trying to modify a programming example and I am coming up with two problems... first is that I can't seem to pass along the arguments to the external command (I have been able to do that with...
8
by: clyfish | last post by:
In cmd, I can use find like this. C:\>netstat -an | find "445" TCP 0.0.0.0:445 0.0.0.0:0 LISTENING UDP 0.0.0.0:445 *:* C:\> And os.system is OK....
0
by: mcoliver | last post by:
I have a python script (script 1) that calls another python script (script 2) which executes a command using os.popen. Everything works flawlessly when executed from the command line. However when...
25
by: Jeremy Banks | last post by:
Hi. I wondered if anyone knew the rationale behind the naming of the Popen class in the subprocess module. Popen sounds like the a suitable name for a function that created a subprocess, but the...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.