paullem has asked for the wisdom of the Perl Monks concerning the following question:

Seeking mystic knowledge:

I am using the Filesys::SmbClientParser module in my program. It is working well with one exception...

I am getting this sprinkled liberally in my output:

Domain=[XXX] OS=[SpinStream2] Server=[Windows 2000 Lan Manager]
What incantation might I chant to exorcise this demon? I have consulted all of the sacred scrolls (Google) to no avail!

SOLUTION: Thanks to monk: your_mother

#!/usr/bin/perl -w use Filesys::SmbClientParser; use Capture::Tiny ':all'; my $smb = new Filesys::SmbClientParser; $smb->Debug(0); $smb->Workgroup('mydomain'); $smb->User('myid'); $smb->Password('mypwd'); $smb->Host('myhost'); $smb->Share('mysharename'); # List content $stderr = capture_stderr { $smb->cd('to/som/directory') or die("cd failed failed: $smb->err, +$!");; }; #<-note the closing ; my @l; $stderr = capture_stderr { @l = $smb->dir or die("List failed failed: $smb->err, $!"); }; #<-note the closing ; foreach (@l) {print $_->{name},"\n";}
And the list of files flow freely without the demonic curses.

Replies are listed 'Best First'.
Re: Suppress unwanted text from Filesys::SmbClientParser
by Your Mother (Archbishop) on Nov 22, 2017 at 04:40 UTC

    That is output from the underlying tool, (/usr/bin/)?smbclient. It's invoked in the private method _List with the -L arg (which gives that output) in methods: GetShr, GetHosts, and GetGroups. It seems to be sent to STDERR. That's why it's in your output and might even seem random since buffering for STDOUT might not match.

    Thing could maybe be rewritten in a modern idiom with Capture::Tiny or something to catch and separate the layers but it is what it is today and what it is is a 15 year old module that does all its calls with `backticks` and it might have issues in general from age or underlying tool drift. You could always redirect STDERR and/or STDOUT in your code, or in the shell where you call your code, to separate the output at least.

      Thank you, it is a bot of a hack but it works perfectly. Thank you!

      I guess it should be another solution in CPAN that uses XS and avoid doing additional system calls with the added value of not having to capture STDOUT and STDERR?

      I didn't search myself, but back in the day I was using Samba I remember that something was available to interact with it using Perl and XS.

      Alceu Rodrigues de Freitas Junior
      ---------------------------------
      "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill
Re: Suppress unwanted text from Filesys::SmbClientParser
by LanX (Saint) on Nov 22, 2017 at 02:18 UTC
      I have set the debug level to 0 to no advantage
Re: Suppress unwanted text from Filesys::SmbClientParser
by 1nickt (Canon) on Nov 22, 2017 at 00:09 UTC

    Hi, second thing I would do (after searching the source of Filesys::SmbClientParser) is install Carp::Always and use it at the top of your script/package. This will tell you exactly where the message originates. Then you can figure out how to suppress it.

    Hope this helps!


    The way forward always starts with a minimal test.
A reply falls below the community's threshold of quality. You may see it by logging in.