Re: sending multiple arguments to shell command with defun andinteractive

"John Bullock" <[email protected]> Thu, 20 Oct 2005 21:39:33 -0700
Newsgroups gmane.emacs.xemacs.general
Message-ID <[email protected]>
> shell-command-on-region passes the contents of the specified region to
> the command's stdin. There doesn't seem much point also passing it as
> a command-line argument.

Of course -- thank you.  Somehow I'd forgotten that I was already passing the
contents of the region to stdin.

Best wishes,
--John


----- Original Message ----- 
From: "Glynn Clements" <[email protected]>
To: "John Bullock" <[email protected]>
Sent: Thursday, October 20, 2005 7:35 AM
Subject: Re: sending multiple arguments to shell command with defun
andinteractive


>
> John Bullock wrote:
>
>> > (shell-command-on-region (point) (mark)
>> >  (format "perl c:/perl/misc/perlhello.pl \"%s\" \"%s\"" old new) nil t)
>>
>> Thank you.  This definitely moves me in the right direction.
>>
>> The only problem that remains for me is that I want the
>> region -- the block of text I've highlighted in XEmacs --
>> to be passed to the Perl script as another argument,
>> joining "old" and "new."  This code more or less does
>> what I have in mind:
>>
>> (defun hello (string_to_replace old new)
>>   (interactive "sString to replace: \nsOld: \nsNew: ")
>>   (shell-command-on-region (point) (mark)
>>       (format "perl c:/perl/misc/perlhello.pl \"%s\" \"%s\" \"%s\""
>> string_to_replace old new) nil t))
>>
>> But it's inefficient.  I want the "string_to_replace" argument to be
>> nothing
>> more than the region I've highlighted.  But with this code, I need to
>> manually
>> re-type that code when prompted for "String to replace: ".  How can I
>> automatically pass the highlighted region to my Perl script?
>
> shell-command-on-region passes the contents of the specified region to
> the command's stdin. There doesn't seem much point also passing it as
> a command-line argument.
>
> Apart from anything else, passing a potentially large amount of text
> as an argument has two potential risks:
>
> 1. Overflowing the OS limitation on the maximum length of a command.
>
> 2. The text may contain quotes, which will interfere with the shell's
> parsing of the command string into individual arguments.
>
> It would be better for the Perl script to read the string from stdin
> than to expect it to be passed as an argument.
>
> -- 
> Glynn Clements <[email protected]>