Welcome to the Monastery | |
PerlMonks |
Re: In Perl, how to check for the remote folder existence using sftp command? Cant use Net:SFTPby haukex (Archbishop) |
on May 25, 2016 at 14:53 UTC ( [id://1164081]=note: print w/replies, xml ) | Need Help?? |
Hi Yedu, At least on my system, the "Couldn't canonicalise: ..." message gets printed to sftp's stderr stream, which the backticks you're using to run the command don't capture, and the sftp command itself exits normally after the "bye", which is why you're not seeing an error in $?. My suggestion would be to switch to a module that is capable of capturing stderr when running the external command. My personal favorites are IPC::Run3 and Capture::Tiny. There's also the core module IPC::Cmd, which I don't have experience with. The "not so nice" solution is to have the shell merge the command's stdout and stderr streams by inserting " 2>&1" just before " <<EOF". Then you should be able to inspect $sftp_log for the error message with a regular expression. Hope this helps,
In Section
Seekers of Perl Wisdom
|
|