I’m trying to execute apps in c by name, before the run
I want to find out if the name are legal. is there any
way to check in c, and find out if the app exist in the PATH environment?
thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Probably the best way to do it is to mimic behaviour of ‘which’ command as Lunar Mushrooms already suggested.
Quick look to output of following command
reveals that ‘which’ simply loops through $PATH entries, concatenates it with command name (‘ls’ in above example) and calls stat64 on it. It breaks loop if stat64 returns something different than -1 (meaning that file exists). Here’s relevant snippet of output from tested command: