は私が私の現在のフォルダ内の任意のtest12.outファイルがイマイチシステムによって実行コマンドのステータス()
#include <sys/stat.h>
#include <stdio.h>
int
main(int argc, char *argv[])
{
int a = system("./test12.out"); //here if i am giving any wrong commad
system("echo $?")
printf("system return is %d",a);
}
私のCコードで一つのシステムコールを使用しています参照を取得する方法。今、出力が
sh: ./test12.out: No such file or directory
0
system return is 32512
がここにある私のシェルコマンドは失敗しましたが、私は私のCコードでどのようにしていることを知ることができますか?
編集:
a == -1
場合ので、私はこの
int
main(int argc, char *argv[])
{
int a = system("dftg");
if(a == -1)
printf("some error is occured in that shell command");
else if (WEXITSTATUS(a) == 127)
printf("That shell command is not found");
else
printf("system call return succesfull with %d",WEXITSTATUS(a));
}
+1、自分の回答を削除しました。 '-1'を別に確認してください。 –
私の編集を参照してください...それは正しいですか? –