Discuss System() output in the C Programming forum on Dev Shed. System() output C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month! Download and Activate to enter!
Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.
Posts: 50
Time spent in forums: 5 h 28 m 8 sec
Reputation Power: 0
System() output
I came across a different little issue that I would like to find a solution.
I am using system() in program1 (yes, I know, bad) to run program2 after formatting it and its arguments with snprintf(). I would have used execl(), but it stops running after the first execution and I need it to run a few times. The program runs a program2 and system() is happy to print its output, fine. But, when and if program2 crashes, it doesn't show that output (like a segmentation fault, etc). I want it to show every detail after execution, just like I would have ran it without using program1, and I want to see the error if the program2 I run crashes, as well.
I hope my problem is understood, if not let me know and I'll try to explain it further. I appreciate your help and solutions as always.
Posts: 50
Time spent in forums: 5 h 28 m 8 sec
Reputation Power: 0
Using those outputs didn't work, but I found I can use execl() and it will show all output, but I guess it returns after execution and I need it to keep going (I need to execute around program2 about 5 times with different arguments). Any way around this?
Posts: 4,405
Time spent in forums: 4 Weeks 1 Day 9 h 41 m 54 sec
Reputation Power: 1719
Quote:
Originally Posted by mokeyjoe
Using those outputs didn't work, but I found I can use execl() and it will show all output, but I guess it returns after execution and I need it to keep going (I need to execute around program2 about 5 times with different arguments). Any way around this?
In what way did they not work? The text was sent to a file (or two separate files).
It is not entirely clear what you mean, or what you want. Whatever you are doing we probably need to know what OS you are using.
execl will behave as documented. How are you using it? In Windows it spawns a process that replaces teh process that spawned it (as documented). If that is not what you wanted, you are using the wrong function. Perhaps you really wanted spawnl(), which spawn an additional process. You can opt to have the process run synchronously or concurrently to the spawning process.
Posts: 50
Time spent in forums: 5 h 28 m 8 sec
Reputation Power: 0
I am using Linux.
program1 runs program2 with "1" as argument #1
program1 runs program2 with "1" as argument #1 and "10" as argument #2
program1 runs program2 with "100" as argument #1
program1 runs program2 with "1" as argument #1, #2, & #3
program1 runs program2 with "0" as argument #1
I need to write code that will do that, basically, all in one program (program1).
As you suggested clifford, execl will replace the current program1 with program2, therefore leaving no control with program1, which program1 needs to run program2 again and again with different arguments.
See my problem now?
Note: I am mostly interested in the error/normal output of the executions.
Thanks!
Last edited by mokeyjoe : February 2nd, 2009 at 02:27 PM.
Posts: 2,770
Time spent in forums: 1 Month 4 Weeks 20 h 17 m 31 sec
Reputation Power: 1237
> but I found I can use execl() and it will show all output, but I guess it returns after execution and I need it to keep going
Did you call fork() before calling exec()?
If not, then you did it wrong, and you would only get one shot.
> Using those outputs didn't work
Thanks for really clarifying it with zero evidence.
Did you see any files created at all, even empty ones?
Did you see the error message, despite attempts to redirect it?
Did you... - got the picture?
Posts: 5,959
Time spent in forums: 2 Months 3 Weeks 2 Days 12 h 47 m 19 sec
Warnings Level: 10
Number of bans: 1
Reputation Power: 0
Mokey? Have you investigated at all the things your are using?
Do you realize that all the **** ups that you are experiencing have been ****ed up lebenty-zillion times before? Do you actuallly think that you have discovered, anew, these various weaknesses?
You would have to work very hard to do that. Previously failures by competent people have resulted in various solutions, some bad some good.
Posts: 2,770
Time spent in forums: 1 Month 4 Weeks 20 h 17 m 31 sec
Reputation Power: 1237
1. Read the manual page for fork(). You're running your test code in the parent, not the child.
2. Read the manual page for execl(). exec functions do NOT deal with command line parsing at all. So if you're trying to pass command line parameters, you need to do more work.
3. Read the manual pages for dup(), pipe() and close() for how to redirect the likes of stdout to a file.
Oh wait, is this just some pseudo-code you bashed in at the keyboard as a quick reply, and has no actual resemblance to your real code?
Posts: 50
Time spent in forums: 5 h 28 m 8 sec
Reputation Power: 0
Code:
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
char small[32], big[128];
int i = 16;
if(strstr(argv[1], "t8")) { i = 8; }
if(strstr(argv[1], "t16")) { i = 16; }
if(strstr(argv[1], "t32")) { i = 32; }
if(strstr(argv[1], "t64")) { i = 64; }
if(strstr(argv[1], "t128")) { i = 128; }
memset(big, 'Z', sizeof(big));
snprintf(small, i, "%s", big);
printf("%s\n", small);
return 0;
}
That is the program I am running through the parent. As you can see, if the values are t64 or t128, the program crashes. I simply want to run that program 5 times with the 5 different values and be able to see the segmentation faults when they occur.
Posts: 5,551
Time spent in forums: 2 Months 2 Weeks 15 h 7 m 7 sec
Reputation Power: 3285
Quote:
Originally Posted by sizablegrin
If you fill a buffer completely with 'Z's and try to treat it as a C-string, what do you suppose will happen?
His program that fills the buffer with 'Z' is intended to crash. It's so he has something that will crash to test whether or not he's capturing the error stream.
As for mokeyjoe, have you read the manual pages and such as they asked?