0

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..

1
  • 2
    You should reverse the order of your IF, because IF ERRORLEVEL 1 matches everything equal or superior to 1. Begin with 4, then 3, 2, 1 Commented Nov 29, 2015 at 22:57

1 Answer 1

3

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 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.