Hello,
I run DOS command "mkdir foo> toto.log.
I creates the directory and log file, but it is empty.
I wish that I put a little message like "foo directory created" or something ...
Thank you for your help!
Hello,
I run DOS command "mkdir foo> toto.log.
I creates the directory and log file, but it is empty.
I wish that I put a little message like "foo directory created" or something ...
Thank you for your help!
Using the return code..
I am not on the syntax but it must be somethingCode:MKDIR TonDossier if% ERRORLEVEL% = 0 Then Echo "Created">> file.log Alejandro Else Echo "Not Created">> file.log End if
Clarification on the redirect command output to a text file:
>: You replace in a text file
>>: You write at the end of file
In both cases, the file is created, so if it is for tracing, both used the ">>"
And finally, know that in theory, any program returns an error code. 0 for success, the rest for chess.
Know that as a developer, it is necessary that your program handles errors, and returns a value other than 0 in this case.
Otherwise, the system will see that your program has finished, and return the value 0, whatever the result.
Thank you for your answer, it has opened a track ...
The syntax is actually not quite correct, but the coup I generate my log file with the sentence that I want.
Except that the tag else is not recognized, and it generates a file test2.log) Not Created with writing inside ...Code:MKDIR test2 if% ERRORLEVEL% == 0 (echo "Created">> test2.log) else (echo "Not Created">> test2.log)
I tried replacing the last line by
But it does nothing in the log if it fails to create the folder ...Code:if% ERRORLEVEL%> 0 (echo "Not Created">> test2.log)
And for info, the only logs that I will generate my logs are existing DOS commands (copy, mkdir, ...) so they must all make a ERRORLEVEL ...
If you are in an NT environment (for the production of your script), I advise you to go on the VBS and not DOS itself.
The VBS is richer and more focused on development. "Bat" ...
And more. "Def" syntax is a little chance ...
Bookmarks