Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Cから新しい非対話型シェルプロセスを起動するにはどうすればよいですか?
現在、私は次のものを持っています:
system(cmdStr); //system("/bin/sh -c");
cmdStrは、実行したいコマンドです。以下にシェルプロセスへの参照があります...しかし、cmdStrを追加するにはどうすればよいですか?新しいプロセスを起動させるにはどうすればよいですか?
文字列を連結したくない場合は、次のようにすることができます。
if (fork()) { execl("/bin/sh", "sh", "-c", cmdStr, (char *) NULL); exit(EXIT_FAILURE); }
これがsystem基本的に行うことです。
system
strcatそれ以外の場合、文字列を連結するには、標準関数とstrncatからを参照する必要がありますstring.h。
strcat
strncat
string.h