Keep Text Filter Output In Original Window

95 views
Skip to first unread message

ctfishman

unread,
Apr 15, 2021, 9:29:42 AM4/15/21
to BBEdit Talk
I have the following perl script as a text filter. It is designed to take the lines being acted on and run each as a unix command. The script does run the commands, but instead of putting the output back in the original file it opens the Unix Script Output log and puts it there. I have a number of other perl filters and none of them do that, however they are not running shell commands within them. Is there a way I can get this script to do what I want?

#!/usr/bin/perl

while (<>) {
    chomp($_);
    if ( length($_) > 2 ) {
        $command = `$_`;
        print $_ . "\n" . $command . "\n";
    }
}

Thanks,
-matt

jj

unread,
Apr 15, 2021, 1:42:18 PM4/15/21
to BBEdit Talk
Hi Matt,

I tested your script.

When placed in the "~/Library/Application Support/BBEdit/Scripts" directory and 
called from the "Script > exec_lines.pl" menu item, it does what you report. It prints to 'Unix Script Output.log'.

But if placed in the "~/Library/Application Support/BBEdit/Text Filters" and 
called from the "Text > Apply Filter > exec_lines.pl" menu item, it behaves as you expect. It prints to the document.

HTH

Jean Jourdain

Message has been deleted

ctfishman

unread,
Apr 15, 2021, 2:45:51 PM4/15/21
to BBEdit Talk
Thanks Jean, but I do have it in the text filters folder and am calling it via "Text > Apply Filter".

On further investigation, it seems to have been because a command I was running generated a warning:

echo "Some Text"
^prints to the document

ssh devserver "echo 'some text'"
^prints to the document

ssh devserver "mysql ..."
mysql: [Warning] Using a password on the command line interface can be insecure.
^prints to the log window

That said, if I run the exact same command in a shell worksheet, the warning prints in the worksheet.

Patrick Woolsey

unread,
Apr 15, 2021, 3:59:30 PM4/15/21
to bbe...@googlegroups.com
This is the expected behavior:

A text filter should accept input on STDIN and return the
processed data (if any :-) on STDOUT, which BBEdit will place
back into the document, whereas if there is any error output,
BBEdit will post that into the script output log (so as not to
adversely affect the document's contents).

[PS: For reference please see the "Filters" section (pg. 355
currently) in Chapter 14 of the PDF manual. :-) ]

[PPS: Shell worksheets by their nature do not redirect error output.]

Regards

Patrick Woolsey
==
Bare Bones Software, Inc. <https://www.barebones.com/>




On 4/15/21 at 2:18 PM, mfis...@casciac.org (Matthew Fischer) wrote:

>Thanks Jean, but I do have it in the text filters folder and am calling it
>via "Text > Apply Filter".
>
>On further investigation, it seems to have been because a command I was
>running generated a warning:
>
>echo "Some Text"
>^prints to the document
>
>ssh devserver "echo 'some text'"
>^prints to the document
>
>ssh devserver "mysql ..."
>mysql: [Warning] Using a password on the command line interface can be
>insecure.
>
>^prints to the log window
>
>
[...older messages elided...]

ctfishman

unread,
Apr 15, 2021, 4:59:37 PM4/15/21
to BBEdit Talk
Thanks Patrick, that explains it. The commands I was running didn't return any output but they did return a warning. That's why I mistakingly thought that everything was going to the log window.

Charlie Garrison

unread,
Apr 15, 2021, 8:00:13 PM4/15/21
to BBEdit Talk

On 16 Apr 2021, at 6:59, ctfishman wrote:

Thanks Patrick, that explains it. The commands I was running didn't return any output but they did return a warning. That's why I mistakingly thought that everything was going to the log window.

If needed, you can get Perl to capture both STDOUT and STDERR from the running $command, and send both back to the document being filtered. I doubt that's what you want (you probably want STDERR going to BBEdit output log), but it's easy enough to grab both if that's preferred.

-cng

--

Charlie Garrison                   <cha...@garrison.com.au>
Garrison Computer Services      <http://www.garrison.com.au>
PO Box 380
Tumbarumba NSW 2653  Australia

ctfishman

unread,
Apr 16, 2021, 8:33:47 AM4/16/21
to BBEdit Talk
Thanks for the tip Charlie. In this case I did in fact want to mimic the way a shell worksheet works. Adding "open STDERR, '>&STDOUT';" to the start of my script did just that.
Reply all
Reply to author
Forward
0 new messages