如何检查路径中是否存在程序 [英] How to check existence of a program in the path
本文介绍了如何检查路径中是否存在程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用scala编写一个程序,调用:
I'm writing a program in scala which call:
Runtime.getRuntime().exec( "svn ..." )
我想检查命令行中是否有svn(即它是可在PATH中到达)。
我该怎么做?
I want to check if "svn" is available from the commandline (ie. it is reachable in the PATH). How can I do this ?
PS:我的程序设计在windows上运行
PS: My program is designed to be run on windows
推荐答案
我不是scala程序员,但我会用任何语言做的,就是执行' svn help
'这样的事情检查exec方法的返回码(0或1)...如果失败则svn不在路径中:P
I'm no scala programmer, but what I would do in any language, is to execute something like 'svn help
' just to check the return code (0 or 1) of the exec method... if it fails the svn is not in the path :P
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("svn help");
int exitVal = proc.exitValue();
按照惯例,值0表示正常终止。
By convention, the value 0 indicates normal termination.
这篇关于如何检查路径中是否存在程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文