---
name: "system_nosh"
section: "3"
platform: "linux"
package: "libexecs-dev"
version: "1.4-2+b2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/system_safe"
---

# system\_nosh(3)

execute a command with its arguments from a string without using a shell

Part of [system\_safe(3)](/system_safe/3.md).

## NAME

system\_safe, system\_execs, system\_nosh - execute a command with its arguments from a string without using a shell

## SYNOPSIS

**#include \<stdlib.h\>**\
 **#include \<execs.h\>**

**int system\_safe(const char \****command***);**\
 **int system\_execsp(const char \****command***);**\
 **int system\_execsa(const char \****command***);**\
 **int system\_execs(const char \****path***, char const \****command***);**

**int system\_execsrp(const char \****command***, int** *redir***\[3\]);**\
 **int system\_execsra(const char \****command***, int** *redir***\[3\]);**\
 **int system\_execsr(const char \****path***, char const \****command***, int** *redir***\[3\]);**

**int system\_nosh(const char \****command***);**\
 **int system\_execsqp(const char \****command***);**\
 **int system\_execsqa(const char \****command***);**

**int system\_execsqrp(const char \****command***, int** *redir***\[3\]);**\
 **int system\_execsqra(const char \****command***, int** *redir***\[3\]);**

These functions are provided by libexecs. Link with *-lexecs*.

## DESCRIPTION

**system\_safe** is a safe replacement for [**system**(3)](/system/3.md) provided by the libc. **system\_safe** parses the command string and runs the command directly, without using a shell. The command must be specified as an absolute pathname. **system\_safe** does not support variables as argument.\
 Command arguments in *args* are delimited by space characters (blank, tabs or new lines). Single or double quotes can be used to delimitate command arguments including spaces and a non quoted backslash (**\\**) is the escape character to protect the next char.\
 **system\_execsa** is like **system\_safe** supporting also variables as arguments. When an argument of a command is a dollar sign followed by a name (e.g. $USER) s2argv puts the output of  the  s2argv\_getvar function instead. (It is possible for example to assign s2argv\_getvar=getenv.  For security reasons, the function is NULL by default and all variables get replaced with an empty string. Programmers can use their own custom function instead)\
 In **system\_execsp** the executable file is sought using the PATH environment variable as explained for [**execlp**(3)](/execlp/3.md).\
 **system\_execs** requires the path of the executable to be specified as its first parameter so it does not use the PATH environment variable.\
 **system\_execsr**, **system\_execsrp** and **system\_execsra** works as their couterparts without the 'r', but they permit the redirection of standard input, output and error streams. Their last parameter is an array of three integers. The standard input of the command will be redirected to **redir\[0\]** if it is positive, the standard output to **redir\[1\]** if it is not negative and different from 1, the standard error to **redir\[2\]** if it is not negative and different from 2.\
 **system\_execsra** does not use the PATH variable, argv\[0\] must be specified as a full pathname.\
 **system\_nosh**, **system\_execsqp**, **system\_execsqa**, **system\_execsqrp** and **system\_execsqra** can run sequences of commands separated by semicolons (**;**). The first command returning a non-zero exit status breaks the sequence.\
 **system\_nosh** is an almost drop in replacement for [**system**(3)](/system/3.md) provided by the libc. (**system\_execsqp** and **system\_nosh** are synonyms).

## RETURN VALUE

These functions have the same return values of [**system**(3)](/system/3.md). When running a sequence of commands, it returns the "wait status" of the first command returning a non-zero value. If the return value is zero it means that all the commands of the sequence succeeded.

## EXAMPLE

The following program shows the usage of **system\_nosh**:

```
#include <stdio.h>
#include <unistd.h>
#include <execs.h>
#define BUFLEN 1024
int main(int argc, char *argv)
{
	char buf[BUFLEN];
	printf("type in a command and its arguments, e.g. 'ls -l'\n");
	while (fgets(buf, BUFLEN, stdin) != NULL) {
		printf("Command: '%s' \n",buf);
		system_nosh(buf);
		printf("Command done\n");
	}
}
```

## SEE ALSO

[**system**(3)](/system/3.md),[**execs**(3)](/execs/3.md),[**s2argv**(3)](/s2argv/3.md)

## BUGS

Bug reports should be addressed to \<info@virtualsquare.org\>

## AUTHOR

Renzo Davoli \<renzo@cs.unibo.it\>
