1.

Solve : how to make a batch file fail???

Answer»

hi

i have created a batch file which checks for a file.
if the file is present it renames the file.

however if the file is not present it says file not present through echo command.

but i need the batch file to fail and return error or failure.

can SOMEONE help me out

abhinav Please post the code you are usingIF EXIST "c:\TRY\a.txt". (
copy "c:\try\a.txt" "c:\try\b.txt"
del "c:\try\a.txt"
echo deleted.

) ELSE (
echo "c:\try\a.txt" missing.
echo try again.

)

If the file is missing then the script should fail but it runs successfully irrespective of the file being present or not What do you mean by "fail"? Why don't you just exit silently if the file to be renamed does not exist?

Did you write the script yourself?
no i want it to return an error... an APPLICATION will use this batch file and will succed or fail in the first step depending on the result of this scriptJust my 2¢:

Is this a TYPO or a stray dot: IF EXIST "c:\try\a.txt". (

If you're trying to test the else condition, rename a.txt before running your code.

Why copy a.txt to b.txt, then delete a.txt? Faster to rename a.txt to b.txt and eliminate the middleman.

Gotta love this post title: how to make a batch file fail??. There are countless examples scattered about the CH DOS board.



not a typo ...this script runs on my comp
yes renaming would be easier but i require to do it this way.

could you just tell me how to make the else part of the script such that if there is no file the script should not run successfully...Try this:

Quote

IF EXIST "c:\try\a.txt". (
copy "c:\try\a.txt" "c:\try\b.txt"
del "c:\try\a.txt"
echo deleted.

) ELSE CRASH

Your script will SURELY fail...thanks ...


Discussion

No Comment Found