Oct 18, 2013 at 2:38pm UTC
I have followed several tutorials on how to fork a child process and launch a program using exec() family functions. When run this code:
1 2 3 4 5 6 7 8 9 10 11 12
int main(int argc, char *argv[])
{
pid_t child = fork();
int ret;
if (child==0){
ret = execl("bin/ls" , "ls" , (char *)0);
printf("failed... ret=%d\n" , ret);
}
return 0;
}
I get the expected output from ls. However, when I try
to run another executable inside /bin, for instance:
1 2 3 4 5 6 7 8 9 10 11 12
int main(int argc, char *argv[])
{
pid_t child = fork();
int ret;
if (child==0){
ret = execl("/bin/fastx_quality_stats" , "fastx_quality_stats" , (char *)0);
printf("failed... ret=%d\n" , ret);
}
return 0;
}
the code returns -1. I am certain that the path is correct. Any ideas?
I should also mention that "fastx_quality_stats" expects other arguments, so the full execl command should look like this:
execl("/bin/fastx_quality_stats" , "fastx_quality_stats" , "-i" , "/home/.../pipeline/data/test2.fastq" , "-o" , "/home/.../pipeline/data/outfile.txt" , "-Q33" , (char *)0);
I've also tried this to no avail
Last edited on Oct 18, 2013 at 3:18pm UTC
Oct 18, 2013 at 3:54pm UTC
Thanks @ne555. The error returned is: "no such file or directory", but I'm not sure why as terminal clearly shows the file inside /bin.
Oct 18, 2013 at 6:55pm UTC
Does it run from the command line with those arguments?
Oct 19, 2013 at 12:27am UTC
Yes. It runs fine from command line. I ran it from command line and then copied and inserted the arguments into execl to be sure.
Oct 19, 2013 at 12:55am UTC
Out of curiosity, I downloaded and compiled fastx_toolkit-0.0.7 and got a ".fq" file from here:
https://wiki.cgb.indiana.edu/display/isga/Sample+FastQ+Files
The following code works fine here (generates an output file):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <unistd.h>
#include <cstdio>
int main(int argc, char *argv[])
{
pid_t child = fork();
int ret;
if (child==0){
execl("/usr/local/bin/fastx_quality_stats" , "fastx_quality_stats" ,
"-i" , "/home/norm/temp/fastq/sample_2.fq" ,
"-o" , "/home/norm/temp/fastq/outfile.txt" ,
NULL);
std::perror("error " );
}
return 0;
}
Not trying to sound patronizing, but the default install directory is /usr/local/bin. Did you supply configure with --prefix=/bin ?
Edit: minor code correction
Last edited on Oct 19, 2013 at 1:58am UTC
Oct 19, 2013 at 2:16am UTC
""Not trying to sound patronizing, but the default install directory is /usr/local/bin. Did you supply configure with --prefix=/bin ?""
Patronize all you like Norm, because it works! I should have looked in the readme. The tools are listed in /usr/bin, but the install directory was /usr/local/bin. Thanks Norm!, and sorry if I wasted anyone's time.