Command at the Windows CMD prompt

Asked

Viewed 21 times

-1

I use the following command at the prompt to unzip the file and at the end close the window. However, when there are no more files, it informs that it has no file and does not close the window.

How to make it close cmd even when it does not find the file?

Code:

dir "c:\home\.7z" /s/b > "c:\output.txt" && exit
  • whereas you want a exit unconditional, if you use a script it might be better to put Exit on a separate line instead of using operators (even for readability).

1 answer

-2

I found it. The operator && is executed when there is success. And with & it executes the next command with or without success.

  • 2

    In fact, the distinction between && and & is because the first being of curto-circuito, that is, as he already knows that will give false (After all, it gave an error saying it has no files) it already returns the result and does not execute the next command. In the other case, it evaluates all results (in this case, executes all commands).

  • 1

    Thank you very much for the notes and adjustments in the names.

  • Please add more details to expand your response, such as a working code or documentation quotes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.