On May 28, 2:56 pm, Chief <blons...@gmail .comwrote:
Hello i would like to know
which syntax do i have to use in order to make a program run other
*.exe program and also how to put inputs in it
for example i want to to make a program that run other file call
try.exe and save all the stdout into a file
thanx
For command line program, Mr Carramba is right. But within a program,
try these stuffs
Your program, a parent process, forks a child and exec's the second
try.exe (with arguments). Close stdout for child and redirect its
output to a file using dup systemcall and pipes.
For more about fork() - see
http://www.erlenstar.demon.co.uk/unix/faq_toc.html#TOC3
Here is a basic code that resembles your problem, though not same
This program pipes the o/p of 1 command to i/p of another
=============== =============== =============== =============== =============== =====
#include<stdio. h>
main(){
int pfd[2] ;
if(pipe(pfd) < 0){
fprintf(stderr, "Cannot Create pipe\n");
exit(0);
}
switch(fork()){
case -1:
fprintf(stderr, "cannot create child\n");
exit(-1);
case 0:
if(dup2(pfd[1] , 1 ) < 0){
fprintf(stderr, "Cannot dup\n");
exit(0);
}
close(0) ;
close (pfd[1]);
close (pfd[0]);
execlp("ls", "ls", "-l", NULL) ;
fprintf(stderr, "Cannot exec 1\n");
default :
break ;
}
switch(fork()){
case -1:
fprintf(stderr, "Cannot fork 2\n");
exit(0);
case 0:
if(dup2(pfd[0] , 0) < 0) {
fprintf(stderr, "Cannot dup 2");
exit(0);
}
close(pfd[0]);
close(pfd[1]);
execl("/usr/bin/wc", "wc", NULL);
fprintf(stderr, "Cannot exec 2\n");
default:
break ;
}
wait ((int *)0) ;
}
=============== =============== =============== =============== =============== =============== ===
Bye
Guru Jois