如何确定一个系统命令可用?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

如何确定一个系统命令可用?

Kevin anew
我想调用 wget 来下载文件,但可能并不是每一台机器都有,有什么方法可以知道这台机器是否可以运行 wget ?

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 如何确定一个系统命令可用?

limodou
On Jan 5, 2008 1:49 AM, Kevin anew <[hidden email]> wrote:
> 我想调用 wget 来下载文件,但可能并不是每一台机器都有,有什么方法可以知道这台机器是否可以运行 wget ?
>
可以执行查看版本的命令来预先执行一下,看能不能得到预期的输出结果。

--
I like python!
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
meide <<wxPython UI module>>: http://code.google.com/p/meide/
My Blog: http://www.donews.net/limodou
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 如何确定一个系统命令可用?

jessinio liang
bash脚本:
  wget

  if [ $? -eq 127 ]
      then
      echo 'Error: no command'
  fi
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 如何确定一个系统命令可用?

Jiahua Huang
bash 下用 which 来确定是否有这命令

which wget || echo 没有 wget
wgich wget &&  echo  有 wget

On Jan 5, 2008 9:51 AM, jessinio liang <[hidden email]> wrote:
> bash脚本:
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 如何确定一个系统命令可用?

jiyong wu
In reply to this post by limodou
if 0 == os.system('wget --version >/dev/null 2>&1'):
        ok
else:
        not ok

On  4, limodou <[hidden email]> wrote:

> On Jan 5, 2008 1:49 AM, Kevin anew <[hidden email]> wrote:
> > 我想调用 wget 来下载文件,但可能并不是每一台机器都有,有什么方法可以知道这台机器是否可以运行 wget ?
> >
> 可以执行查看版本的命令来预先执行一下,看能不能得到预期的输出结果。
>
> --
> I like python!
> UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
> meide <<wxPython UI module>>: http://code.google.com/p/meide/
> My Blog: http://www.donews.net/limodou
> _______________________________________________
> python-chinese
> Post: send [hidden email]
> Subscribe: send subscribe to [hidden email]
> Unsubscribe: send unsubscribe to  [hidden email]
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 如何确定一个系统命令可用?

Lich_Ray
这个方法又会启动一下进程,浪费中的浪费,Python 又不是 Shell。

在08-1-8,wu jiyong <[hidden email]> 写道:
if 0 == os.system('wget --version >/dev/null 2>&1'):
        ok
else:
        not ok

On  4, limodou <[hidden email]> wrote:

> On Jan 5, 2008 1:49 AM, Kevin anew < [hidden email]> wrote:
> > 我想调用 wget 来下载文件,但可能并不是每一台机器都有,有什么方法可以知道这台机器是否可以运行 wget ?
> >
> 可以执行查看版本的命令来预先执行一下,看能不能得到预期的输出结果。
>
> --
> I like python!
> UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
> meide <<wxPython UI module>>: http://code.google.com/p/meide/
> My Blog: http://www.donews.net/limodou
> _______________________________________________
> python-chinese
> Post: send [hidden email]
> Subscribe: send subscribe to [hidden email]
> Unsubscribe: send unsubscribe to  [hidden email]
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese



--
Ray Stinger, nickname Lich_Ray
God is in his heaven, all's right with the world.
-------------------------------------------------
let focus = 'computing' in where:
http://lichray.javaeye.com
let focus = 'computing' in here:
http://lichray.bokeland.com
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese