execl() problem when trying to spawn program

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
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.

Does it run from the command line with those arguments?
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.
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
""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.
Topic archived. No new replies allowed.