exec() with executable shell scripts

Maarten Litmaath maart at cs.vu.nl
Sat Apr 22 13:04:54 AEST 1989


martin at mqcomp.oz (Martin Foord) writes:
\Everytime I seem to exec() a shell script that is executable I have problems
\(execepting if I use execlp() or execvp()).

The shell script doesn't start with the magic number #! or your kernel
doesn't recognize it, hence you get ENOEXEC ("Exec format error"), as you
would have known, had you put a call to perror() in your C program.
On the other hand, after having received an exec format error EXECVP()
decides the file must be a shell script, and executes /bin/sh with the file
as first argument. Hence execvp() works.

\...
\	execv("/bin/true",args);
\	printf("Can't execute process\n");

Thanks a lot for that *VERY* helpful error message! :-(
Instead do:

	perror("/bin/true");

If you are a Real Programmer, add:

	*(char *) -1 = 0xDEAD;

and read the hexdump with breakfast! :-)
-- 
 "If it isn't aesthetically pleasing, |Maarten Litmaath @ VU Amsterdam:
  it's probably wrong." (jim at bilpin). |maart at cs.vu.nl, mcvax!botter!maart



More information about the Comp.unix.wizards mailing list