linux下popen执行系统指令脚本

#!/bin/bash
workdir=$(cd $(dirname $0); pwd)
##适配高并发  modified by chenzhang
#time_flag=`date "+%Y%m%d_%H%M%S"`
time_flag=`uuidgen`
input_result=$workdir/${time_flag}_input
output_info_result=$workdir/${time_flag}_output_info
output_error_result=$workdir/${time_flag}_output_error

#run cmd
##适配管道命令 modified by chenzhang
#cmd_run=`LC_ALL=en_US LIBGUESTFS_BACKEND=direct $1 1>$output_info_result 0>$input_result 2>$output_error_result`
cmd_run=`LC_ALL=en_US LIBGUESTFS_BACKEND=direct sh -c "$1" 1>$output_info_result 0>$input_result 2>$output_error_result`

#get result after cmd was running
cmd_result=`echo $?`

#get std string after cmd was running
input_result_string=`cat $input_result 2>/dev/null`
output_info_result_string=`cat $output_info_result  2>/dev/null`
output_error_result_string=`cat $output_error_result  2>/dev/null`

#print result
echo "result=$cmd_result"

#print std string
echo "input_result=$input_result_string"
echo "output_info_result_string=$output_info_result_string"
echo "output_error_result_string=$output_error_result_string"

#delete std file
rm -f $input_result $output_info_result $output_error_result  2>/dev/null

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值