linux - Redirect stdout to stderr in shell -
i unable shell command output ran on ssh.
for example
output=$(utility_function ssh $host "pwd 2>&1" 2>&1)
the problem run ssh command, utility_function , utility_function returns "exit code" in stdout. so, because stdout being, used function exit code that's why can't able command output. trying redirect stdout stderr command i'm not capturing output.
output=$(utility_function ssh $host "pwd 2>&1" 2>&1)
the problem in functions, , without more info can't there. if know how, can clone stdout file descriptor 3, , have functions use it, instead of &1 write exit code. also, if function isn't written right, redirect being ignored-- no way know info.
assuming don't, need not redirect pwd command, , instead filter out return code-- if this, lose echo'd return codes function.
this work no matter how function written-- though guessing @ number on tail, b/c don't know how output being spit out disconnect. it's hard troubleshoot blind function , how works. read -r output < <(utility_function ssh $host "pwd" |tail -2|head -1)
you can juggle file descriptors this, , if function uses redirect in string send, should work.
output=$(exec 3>&2; utility_function ssh $host 'pwd >&2' 2>&1 1>&3)
if neither of work, output of what's going on , more data required.
Comments
Post a Comment