0

How can I check if a command can be successfully executed without actually executing it? For example, if i want to connect to another host using telnet connection, how do i check if telnet client exists or not? Or if I want to do a cp or mkdir or rmdir, how do I check if any of these commands can be valid before executing them?

2
  • Access the system PATH variable, split by folder-name, and check to see if foldername+command exists? Commented Mar 28, 2013 at 8:53
  • you could also try if exists also if you type if/? in cmd you can find some info there Commented Oct 11, 2013 at 1:01

1 Answer 1

3

You can always run

which telnet

this will tell you the actual file that would be executed. However, it will not tell you if the command will run with success. For instance, which cp will only tell you where the executable is and not if the files being copied exist and you have the right to copy them to the chosen destination.

Hope this helps

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

1 Comment

So, in general, if there is a <command_name>, i need to check if <command_name> exists or not by executing which <command_name>. Is that what you are saying?

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.