-1

I want to call an executable from a C application . Here is my code:

execl("/home/ion/workspace/DNS/Debug","DNS","216.58.198.164","A",(char*)NULL);

where IP and "A" are supposed to be argv[1] and argv[2]

This application called DNS is supposed to write something an a file , but it's not working when I call it with execl like that . Can anyone help me please?

joesid
  • 671
  • 1
  • 10
  • 21
  • If you [read the `exec` manual page](http://man7.org/linux/man-pages/man3/exec.3.html) you will see that the argument list must be terminated with a `NULL` pointer. – Some programmer dude Feb 28 '17 at 09:51
  • @Someprogrammerdude Still not workng – joesid Feb 28 '17 at 10:00
  • Then can you elaborate on the "not working" part? Do the `execl` call fail (i.e. it returns `-1`)? If so what is the value of `errno` (print it out using e.g. `perror`)? And if possible, please try to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve) and show us. – Some programmer dude Feb 28 '17 at 10:25
  • Also, please tell us what `/home/ion/workspace/DNS/Debug` is, is it a directory or a program? Is the argument `"DNS"` the name of the program, or is it supposed to be the first argument to the program? Can you please show us how you would run the command directly from a shell? – Some programmer dude Feb 28 '17 at 10:31
  • 1
    The first argument has to include the name of the program: `execl("/home/ion/workspace/DNS/Debug/DNS","DNS","216.58.198.‌​164","A",(char*)NULL‌​);` – chus Feb 28 '17 at 12:05

1 Answers1

1

Your application name (DNS) should be specified in the 1st argument (path)

execl("/home/ion/workspace/DNS/Debug/DNS","DNS","216.58.198.164","A",(char*)NULL);
zguesmi
  • 321
  • 1
  • 11