LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   calling another program alongwith arguments using execl not working (https://www.linuxquestions.org/questions/programming-9/calling-another-program-alongwith-arguments-using-execl-not-working-329587/)

sebythomas 06-02-2005 10:48 AM

calling another program alongwith arguments using execl not working
 
Hi,
Been at the problem for 2 long with no solution.Problem description : I have a core program written in GNU C having arguments where wild characters(-f file.*) is passed; the program uses getopt option to assess the arguments. This program is required to be called by a front end graphic interface built using libglade. I tried using execl and it's variants ; I have gone thru relevent man pages ; passing arguments and calling the program works with all other arguments except the ones where wild characters are used; Pl help :Pengy:

Hko 06-02-2005 12:37 PM

Re: calling another program alongwith arguments using execl not working
 
Quote:

Originally posted by sebythomas
passing arguments and calling the program works with all other arguments except the ones where wild characters are used
That's correct. Wildcards are processed by a shell, and exec..()-functions do not run the command inside a shell. This would be a chicken-egg problem, as shells themselves are written in C and need exec..() to run other processes....

Simplest solution:
Use system() instead of one of the exec..()-functions. System() does run the program inside a shell.

If you cannot use system(), because its functionality is too limited for you purpose, check out these functions (ordered from most sophisticated, to most basic):

man 3 wordexp
man 3 glob
man 3 scandir + man 3 fnmatch
man 3 opendir + man 3 readdir + man 3 fnmatch

Hope this helps.


All times are GMT -5. The time now is 09:24 PM.