Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
586 views
in Technique[技术] by (71.8m points)

return value of system() in C

I am using the system() command in C to execute commands like sc query mysql or net start mysql.

If the parameter is null pointer then it returns 1 if the cmd processor is OK, otherwise it returns 0. On successful command execution it returns 0.

My question is: Can I get a list of its return values? Like what it will return if the command is invalid or what the return value on unsuccessful execution will be? I want to do different things depending on the return value of system().

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As the docs state system() return -1 if creating the new process for the command to be executed fails, otherwise it returns the exit code of the command executed. this is the same value you can retrieve using echo $? in unix or echo %ERRORLEVEL% in windows after executing the same command in a shell. So if you want to handle the return values you have to look at what the commands executed return.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...