By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,402 Members | 1,107 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,402 IT Pros & Developers. It's quick & easy.

execl

P: 9
I have a problem calling a compiled program (for example hello.exe which stands for hello world) from another program (let's say time.exe) with execl function


/* program time.c */
#include <stdio.h>
#include <unistd.h>

main (int argc, char *argv[])

{
int i;

execl(argv[i], (char *) 0);
}


although it compiles,

when I call it with command ./time -hello it produces no output but segmentation fault. I am using bash shell


thank you all guys
Apr 20 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 10K+
P: 11,448
I have a problem calling a compiled program (for example hello.exe which stands for hello world) from another program (let's say time.exe) with execl function


/* program time.c */
#include <stdio.h>
#include <unistd.h>

main (int argc, char *argv[])

{
int i;

execl(argv[i], (char *) 0);
}


although it compiles,

when I call it with command ./time -hello it produces no output but segmentation fault. I am using bash shell


thank you all guys
Better make that:
Expand|Select|Wrap|Line Numbers
  1. execl(argv[1], argv[1], null);
and leave out the minus sign on your command line:
Expand|Select|Wrap|Line Numbers
  1. ./time hello
Note that your local variable 'i' isn't initialized; I replaced it with a literal 1.

kind regards,

Jos
Apr 21 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.