python中使用os.system, perl中如何调用到命令行并用getopts解析。

python中使用os.system, perl中如何调用到命令行并用getopts解析。,第1张

以前遇到类似的问题给你一个强有力的解决办法。
用python建立一个临时

shell脚本
。里面放上你所需要所有调用。然后通过python的ossystem再调用这个临时的shell脚本。
如果还有
问题,就是你perl的问题。
记得要用chmod将shell脚本设置成可以执行。

#!/bin/bash
function usage()
{
echo "USAGE: disk_usagesh [-a -n N] directory"
exit
}
function show()
{
dir=$1
if [[ $showall == "true" ]];then
ls -l --color=auto $dir
else
ls -l --color=auto $dir | grep -v total | head -n $shown
fi
}
showall=false
shown=10
while getopts 'an:' opt; do
case $opt in
a)
showall=true
;;
n)
shown=$OPTARG
;;
)
usage
;;
esac
done
shift $(($OPTIND - 1))
if [[ -z $1 ]] || [[ ! -d $1 ]];then
usage
fi
show $1


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/yw/13341657.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-18
下一篇 2023-07-18

发表评论

登录后才能评论

评论列表(0条)

保存