0

I need help with my if command in my file converter. I keep changing the command a bit, but it just returns with

(exit) was unexpected at this time.

And then it closes command prompt. The if command is:

if %success% == 0 (exit) else (goto converter)

Please help.

2
  • 1
    In cases like this, be sure to remove or comment out ECHO OFF statements so that the processing will be shown. At the end of a .bat script, you probably want EXIT /B. See EXIT /?. Commented Apr 16, 2017 at 12:43
  • If you just want to terminate the batch script and not close the command window then use GOTO :EOF instead of exit. EOF is an implicit label at the very end of any batch file. Commented Apr 17, 2017 at 13:10

2 Answers 2

2

In all probability, success is not assigned, ie. set to nothing

if "%success%"=="0" (exit) else (goto converter)

should succeed - but remember exit will terminate the cmd session...

Sign up to request clarification or add additional context in comments.

5 Comments

Okay, that didn't work but i fixed it. I needed to type "if "%success%" == "0" (exit)"
I can't see a difference. Surrounding a string in backticks will shade the background, single-* will italicise and double-* make bold. May help with the quote-count.
I added spaces.
Hmm - it might be that if you are using a word-processor like utility to edit your code the quotes may be being converted to "smart quotes". This will work after a fashion because it makes the first string non-empty, but if the contents of that string include a space (as may be set by a set /p command) it would fail. The quotes need to be strictly " as used by editors like notepad++ or editplus (amonst others). Afraid a venerable old program just doesn't quite get these new-fangled ideas. If this is the case as I suspect, the spaces are optional.
It was Notepad++ set to Batch.
0

Instead of using goto use call and write exit after the if - else condition

set /A success=1
if %success%==0 ( exit ) else ( call :converter )
exit
:converter
echo In Conveter Function
pause

At the end of If-Else you must write exit otherwise converter function will be called twice

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.