[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] cd erstatning



Jeppe Larsen <sslug@sslug> writes:

>> Jeg kan ikke lige se hvordan det skule kunne lade sig gøre.
>
> Så forstår man bedre hvorfor han kan love en kasse øl ;) Men det kan da
> være det netop er pointen at man ikke kan, da vi netop har haft om
> processer.

Med mindre man altså snyder:

#include <stdio.h> 
#include <stdlib.h> 
#include <unistd.h> 
 
int main(int argc, char *argv[]) 
{ 
  if(argc != 2) 
  { 
    printf("Usage is: chdir <directory>\n"); 
    exit(1); 
  } 
 
  printf("Trying to change directory to %s\n", argv[1]); 
  int r = chdir(argv[1]); 
 
  if(r != 0) 
  { 
    printf("An error has occured\n"); 
    exit(1); 
  } 
 
  printf("Directory succesfulled changed to %s\n", getcwd(NULL,0)); 

  char *shell = getenv("SHELL");
  
  if (execlp(shell,shell,NULL) != 0) {
          perror("Couldn't exec $SHELL");
          exit(1);
  }
  
  exit(0); 
} 

-- 
 Peter Makholm     |      I laugh in the face of danger. Then I hide until
 sslug@sslug |                                          it goes away
 http://hacking.dk |                                             -- Xander


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2006-01-01, 02:01 CET [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *