Command line return value

I have a problem and I don’t know if my program is correct or not. Please let me know your ideas?

Problem. Create a process file file on the command line, and the program return is the number of files processed.

My program: in the main () function, I return the number of processed files.

Is it correct? If correct, how can I get this value from another program?

Please help me?

+3
source share
3 answers

You can just use return. The total return value for success is 0, and everything else is considered some kind of error.

int main()
{
 ...

return 0;
}

, , http://en.wikipedia.org/wiki/System_(C_standard_library)

bash script :

, :

  myProgram; 
    V=$?; 
    program1 $V
+5

main() " " ()

#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
    cout<<"Program will exit";
    exit(1); // Returns 1 to the operating system

    cout<<"This line is never executed";
}

, ( - ):

@echo off
call yourapp.exe
echo Exit Code = %ERRORLEVEL%
+3

. - main.

0

All Articles