View Single Post
Old 07-25-2003, 01:13 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,712
redhead is on a distinguished road
You want the code for it? or what??
Code:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv)
{
  int ret=0;
  if(argv != 3)
  {
     printf("Usage %s [directory] [program]\n", argv[0]);
     return -1;
  }
  if(!chdir(argv[1]))
     if(!(ret=system(argv[2])))
        return 0;
     else
     {
        printf("Failure executing %s\n", argv[2]);
        return ret;
     }
  else
  {
     printf("Failure changing to %s\n", argv[1]); 
     return -1;
  } 
}
Or do yu want a more complex code, where you dup(), fork(), write(), read() and waitpid() for the program execution. So you capture everything your external execution does.

Can't .NET compile to something like a [selbstendiger/Selvstændig] app, sorry can't remember the english name..
Else get Cygwin
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote