Collections:
Other Resources:
Run Second Command If the First Successful
How to run two commands with a condition that the second one will run only if the first one is successful?
✍: FYIcenter.com
You can run two commands with a condition that
the second one will run only if the first one is successful
with the syntax below:
command-1 && command-2
For example, if you want to run the "ftp" command only after the "ping" command is successful to reach a remote server, you can use the following command line:
ping host-name && ftp host-name
If you try this with a working FTP server, the "ftp" command will be executed:
C:\fyicenter>ping localhost && ftp localhost
Pinging localhost [::1] with 32 bytes of data:
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Ping statistics for ::1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
Connected to localhost.
220 Welcome to My FTP Server
User: Guest
Password: ******
ftp>
If you try this with a FTP server that is not reachable, the "ftp" command will not be executed:
C:\fyicenter>ping junkserver && ftp junkserver Ping request could not find host junkserver. Please check the name and try again.
⇒ Run Second Command If the First Fails
2022-12-03, ∼2860🔥, 0💬
Popular Posts:
How to use IMDisplay to display an image file? If have image file called wizard.jpg and want to use ...
What is the scheduled task "\Microsoft\Windows\Sysm ain\WsSwapAssessmentTask "on my Windows 8 compute...
What is "SPP Notification Service" in my Windows 7 service list? And how is "SPP Notification Servic...
Can I disable Windows service "DCOM Server Process Launcher" to speedup my computer? Windows service...
What is "Microsoft SharePoint Workspace Audit Service" in my Windows 7 service list? And how is "Mic...