#!/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
linux下popen执行系统指令脚本
最新推荐文章于 2025-03-12 13:38:10 发布