zam
zam

Reputation: 191

How to get input from a c program to a batch file as return value

How to get input from a c program to a batch file as return value to access menu by selecting a number among 1 - 4 . The numbers are given as user input in c file.

For example:

:START

start cChoice.exe

IF ERRORLEVEL 1 GOTO ONE 
IF ERRORLEVEL 2 GOTO TWO 
IF ERRORLEVEL 3 GOTO THREE 
IF ERRORLEVEL 4 GOTO FOUR

:ONE ECHO ONE Start notepad %1 exit /b %ERRORLEVEL%

:TWO ........

Help Plz. I am new in Batch..

Upvotes: 0

Views: 201

Answers (1)

Clifford
Clifford

Reputation: 93456

The return value from main() is the value of ERRORLEVEL. Alternatively the value passed to the exit() function.

However the start command causes the process to run concurrently to the batch file in a different cmd instance, so the batch file will not receive the errorlevel. You should have:

:START
cChoice.exe

IF ERRORLEVEL 1 GOTO ONE 

Upvotes: 3

Related Questions