Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the IPC-System-Simple CPAN distribution.

Report information
The Basics
Id: 37683
Status: resolved
Priority: 0/
Queue: IPC-System-Simple

People
Owner: PJF [...] cpan.org
Requestors: IKEGAMI [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.12
Fixed in: 0.13



Subject: Invokes shell when it says it doesn't
According to your documentation, "system($cmd, @args);" executes the command while "avoiding the shell", but that's not always true. The following code doesn't execute the specified program, passing it to the shell as a shell command instead. use IPC::System::Simple qw( system ); my $cmd = q{notepad > foo}; my @args = (); system($cmd, @args); I don't consider this just a documentation bug. The module is useless to me if it doesn't provides a means of avoiding the shell (both for capturing and not).
G'day ikegami, On Mon Jul 14 22:53:40 2008, ikegami wrote: Show quoted text
> According to your documentation, "system($cmd, @args);" executes the > command while "avoiding the shell", but that's not always true.
You're quite right here. IPC::System::Simple tries to use similar semantics to Perl's built-in system(). Unfortunately, it's so similar it also duplicates some of the bugs. Both suffer the identical problem with: system($cmd, @args); calling the shell when @args is an empty list. The built-in provides an ugly way around this by having the "exotic" form of system, but that's not an option to me, since the exotic form of system can't be prototyped. There are a few work-arounds that sometimes get seen, notably by appending the empty string or "--" to the argument list (depending upon the command and the OS). However they're clunky, ugly, and not "simple", which is what this module is all about. Show quoted text
> I don't consider this just a documentation bug. The module is useless to > me if it doesn't provides a means of avoiding the shell (both for > capturing and not).
I can create an interface into IPC::System::Simple for system/capture that never invokes the shell. The hard part here is determining the name for such an interface. The following are verbose and obvious, but I think are too ugly: noshell_system(...); noshell_capture(...); I'm tempted by: systemx(...); capturex(...); or: xsystem(...); xcapture(...); because they're only a single keystroke different, they still read nicely, and the the 'x' fits nicely into my brain as being short for "exclude the shell". Suggestions for better names highly appreciated, especially since I'd like to implement said interface by OSCON (next week). Another option is extending the interface a little by allowing special symbols in the list of exit values, eg: system( [ NO_SHELL ], $cmd, @args); However this feels very inelegant, and not at all simple. Of course, what I'd *really* like is for the code to actually Do What I Mean when one writes: system($cmd, @args); capture($cmd, @args); That's a hard problem, because once we're inside system/capture, I don't know of any way that allows me to tell if @args was absent, or merely empty, especially if I want to retain backwards compatibility with 5.6.0. I don't consider using source filters to achieve this to be a good idea. Further thoughts, suggestions, feedback, and patches[1] are all very welcome. Many thanks, Paul [1] http://github.com/pfenwick/ipc-system-simple/tree/master is the source repository for the module.
On Tue Jul 15 00:30:03 2008, PJF wrote: Show quoted text
> I'm tempted by: > > systemx(...); > capturex(...);
FWIW, I think systemx() is better than xsystem(). It sorts next to system() when doing keyword completion, and it *looks* more like system() to me, which means it mentally gets less in the way when trying to skim code.
Subject: Re: [rt.cpan.org #37683] Invokes shell when it says it doesn't
Date: Tue, 15 Jul 2008 01:05:08 -0400
To: bug-IPC-System-Simple [...] rt.cpan.org
From: "Eric Brine" <ikegami [...] adaelis.com>
On Tue, Jul 15, 2008 at 12:30 AM, PJF via RT <bug-IPC-System-Simple@rt.cpan.org> wrote: Show quoted text
> The hard part here is determining the name for such an interface.
I agree, thus the lack of suggestion in my bug report. Nothing compelling comes to mind. Show quoted text
> I can create an interface into IPC::System::Simple for system/capture > that never invokes the shell.
Have you considered not invoking the shell by default? or ever? (The user can always execute "sh" explicitly.) It's just an idea, but I like forcing people to realize the shell is involved. ELB
On Tue Jul 15 01:06:40 2008, ikegami@adaelis.com wrote: Show quoted text
> Have you considered not invoking the shell by default? or ever? (The > user can always execute "sh" explicitly.) It's just an idea, but I > like forcing people to realize the shell is involved.
For me personally, never implicitly invoking the shell would be wonderful. Unfortunately, it's not a change I can make in IPC::System::Simple without breaking other people's code, as well as my own. One of the big selling points for IPC::System::Simple is that one can write: use IPC::System::Simple qw(system); at the top of existing code, and all calls to system() continue to work the same way[1], but they now throw exceptions if something goes wrong. It's especially useful to retrofit better error checking onto legacy code. Having single-arg system start avoiding the shell means all the code out there which relies upon that "feature" becomes incompatible with IPC::System::Simple. It stops being an easy solution to fix-up legacy code. Cheerio, Paul [1] Except for the exotic form, which turns into an obvious syntax error.
G'day ikegami, I've added systemx() and capturex() to the development version of IPC::System::Simple. You can grab a pre-release tarball at: http://github.com/pfenwick/ipc-system-simple/tarball/master (Apologies for the ugly filename it will give you), or if you have git installed, you can clone the repository with: git clone git://github.com/pfenwick/ipc-system-simple.git You can safely ignore the warning about missing the META.yml files, this is automatically generated by my build system for stable releases. Note that capturex() and systemx() are not yet fully documented in the dev version at the moment. They will be before the final release. All the existing tests pass with the new code, as do my (rather minimal) extra tests in t/12_systemx.t, at least on my Linux, WinXP, and cygwin systems. It should be noted that capture() under Windows has never invoked the shell, however it *does* use the presence of additional arguments to determine if it should treat the first argument as a command or a command-line. capturex() will force it to always be treated as a command, so: capturex("ipconfig /all"); will fail (the command ipconfig /all doesn't exist), whereas: capture("ipconfig /all"); will fail. There may still be bugs in the dev version of IPC::System::Simple; my brain is partially fried form having spent the entire day preparing slides for OSCON, so I haven't had a chance to look over the alterations with the diligence and clarity I would like, which is partially reflected in the short 12_systemx.t tests right now. If you do spot any problems, let me know. IPC::System::Simple 0.13 should be released to the CPAN by the end of the week, since I'll be relying upon systemx() and capturex() existing for OSCON. Many thanks again for the bug report, Paul
On Tue Jul 15 04:39:19 2008, PJF wrote: Show quoted text
> capturex("ipconfig /all"); > > will fail (the command ipconfig /all doesn't exist), whereas: > > capture("ipconfig /all"); > > will fail.
D'uh! The capture() example there will succeed. Even though it doesn't invoke the shell, IPC::System::Simple extracts the command from the command-line, searches the path, and calls "ipconfig.exe". capturex() should still search the path, but will assume the first argument is the full command name. Cheerio, Paul
G'day ikegami, IPC::System::Simple has just hit the CPAN, and will soon be reaching a mirror near you. It provides runx(), systemx() and capturex() which work just like their namesakes, but never invoke the shell, even if called with only one argument. As such, I'm marking this bug as resolved. You've also got an acknowledgement in the changelog. If you feel this is in error, then I'm sure you already know that responding to this e-mail will re-open the ticket. ;) Many thanks again for the report. May you do good things with IPC::System::Simple. All the very best, Paul