0

I am writing a C program in linux.

I have created a process and forking it to create a child. I want to run another program in this child so I am using execlp. But, this program must run in an independent window.

if ( (execlp("xterm","xterm","-e","./Child1", "127.0.0.1", (char *) 0)) < 0)  {
  printf("Failed to Start the Echo Client. Exiting application.");
  return 1;
}

Child1.c is a simple program which is in the same directory as my current file.

On execution the code runs fine with the xterm window coming up but I get an error "xterm: Can't execvp: No file or directory"

Can you please suggest me a resolution?

Marco Leogrande
  • 8,050
  • 4
  • 30
  • 48
Rahul Dhamecha
  • 23
  • 1
  • 1
  • 7

1 Answers1

0

Your system might not have an xterm installed (or the user has a wrong PATH). You could test the existence of /usr/bin/xterm (with e.g. the access syscall), or use something else. For example, many Debian or Ubuntu distributions have a x-terminal-emulator (which is usually a symlink to some precise program) which you could use instead of xterm.

If xterm fires up, then your program ./Child1 does not exist, you should test its existence (with access) before. If you only have a source code ./Child1.c you should have compiled it before (perhaps by running a system("gcc -Wall Child1.c -o Child1") before and testing that it has compiled successfully, i.e. test that system returns 0 and that the Child1 file exists and is executable).

You should take time to read the xterm(1) man page.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • my sytem has an xterm because when I simply type xterm in the ubuntu command line I see a new window. – Rahul Dhamecha Oct 03 '12 at 05:28
  • Can you tell me what u mean by wrong PATH? Am I supposed to set the path somewhere? Pardon my comments; I am new to linux programming – Rahul Dhamecha Oct 03 '12 at 05:29
  • If you do run `xterm -e ./Child1` on the command line, what is happenning? If you just run `./Child1` what is happenning? And `PATH` is explained in http://www.tldp.org/LDP/abs/html/ – Basile Starynkevitch Oct 03 '12 at 05:32
  • Hi Nothing is happening when I type xterm -e ./Child1. But when I do xterm ./Child1, I get an error saying that "No Absolute Path found for shell" and a new window opens up. – Rahul Dhamecha Oct 03 '12 at 05:56
  • I wasnt creating the output object file Child1 because of which this error came up. Thanks a lot for your help. I appreciate it. – Rahul Dhamecha Oct 03 '12 at 07:54
  • `Child1` is not an object file, but should be some executable binary ELF file. – Basile Starynkevitch Oct 03 '12 at 08:03