# URGENT: It works on linux but not on freeBSD, what could be wrong?



## lasthope (Nov 12, 2019)

I'm posting this here as a last hope, I have a deadline which will expire in a few hours and I've tried everything and can't seem to figure it out.

When I call `system("cc d.c -o d")`, I get



```
unable to execute command: Executable "" doesn't exist!
```

But there's some things to note here,

When program A is executed, it creates/writes d.c. After the write is complete, then program A calls

```
system("cc d.c -o d")
```
Any ideas?


----------



## SirDice (Nov 12, 2019)

lasthope said:


> When I call system("cc d.c -o d")


In what language? There are a million and one languages that have a `system()` call.


----------



## lasthope (Nov 12, 2019)

SirDice said:


> In what language? There are a million and one languages that have a `system()` call.



in c


----------



## SirDice (Nov 12, 2019)

Are you sure it's the `system()` call that's producing the error? Have you tried to execute something else?


----------



## lasthope (Nov 12, 2019)

SirDice said:


> Are you sure it's the `system()` call that's producing the error? Have you tried to execute something else?



Yes, here's what I've tried:
system("ls"); // works
system("ls -la"); //doesn't work
system("ls -la\n"); //works
system("cc"); //works, asks for missing files
system("cc d.c"); //error
system("cc d.c\n"); //error

This is all in fileA, another thing to note:.

I also have fileB and the system calls work fine on there.

I'm really not sure what the relevant difference is between them.


----------



## stratact (Nov 12, 2019)

lasthope, may we see the entire source code?


----------



## SKull (Nov 12, 2019)

Try replacing cc with clang.


----------



## pboehmer (Nov 12, 2019)

Looking at your examples, it appears the common issue is when you are passing arguments along with the command.  A quick google seems to indicate (for whatever reason) that you should put the command in a string and then pass the string in the system call, like:

```
char buf[128];
snprintf(buf, sizeof(buf), "echo %d",a);                                  
system(buf);
```
Worth a try at least.


----------



## Alain De Vos (Nov 12, 2019)

Try giving the full path.
E.g. /usr/local/bin/gcc10


----------



## lasthope (Nov 12, 2019)

UPDATE:
If I do 
system("cc d.c -o d\n"); 

I get "execve error"


----------



## tanis (Nov 12, 2019)

Unfortunately I cannot reproduce your error, which means it is related to your execution environment.

The following works just fine for me:


```
/*
 * system.c
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

int main (int argc, char **argv)
{
    if ( system("cc -o exec.system system.c") < 0 )
    {
        fprintf(stderr, "error: system call: %s\n", strerror(errno));
        exit(EXIT_FAILURE);
    }

    return EXIT_SUCCESS;
}
```


----------



## kpedersen (Nov 12, 2019)

I have encountered this issue once before but got busy with other things and never quite got time to figure out what was going on.

Perhaps avoid the problem entirely and use *popen* instead?

Perhaps try changing your shell before you run the program? Just changing the variable might be enough.

`SHELL=/bin/sh ./myprogram`

Would be quite satisfying to finally put this mystery to rest


----------



## shkhln (Nov 12, 2019)

First, per documentation _system_ is supposed to use _sh_. Second, "unable to execute command" is an error message from the compiler itself. Third, OP is obviously withholding information.


----------



## lasthope (Nov 13, 2019)

Thanks everyone. I found the issue:

I had started program A with execve but did not correctly pass arguments to the env parameters.

After I fixed that, I was able to call system from program A without issue.


----------

