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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -