Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Capturing command output without invoking the system shell: potential pitfalls?

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Perl you can do this:



By reading from STDOUT (or STDERR) you can look at the output of external commands, without running them through the shell via backticks.

The thing is, I have never seen this recommended anywhere for anything. Are there hazards associated with doing this? If so, what are they? Is there a better way of e.g. setting up pipelines in Perl (or other scripting languages) that does *not* rely on the system command shell?

(Also, is the above portable to Windows?)
 
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the closest I could get in Windows:



When you call system, you are still calling an external command. I'm not sure what you get with that syntax that you don't get with the above code.
 
Daniel Levine
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You get command invocation *without using the shell* with somewhat less cumbersome syntax. When you invoke system() on a list rather than a string, it bypasses the shell when running the external command.

Though you can do the same with open in current Perl versions, the syntax is just a bit clunky:



Or something like that. Cool to hear opening pipelines works on Windows anyway.
 
Knute Snortum
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't do that in Windows. You get a List form of pipe open not implemented error. But then if you're doing external calls, it's not really portable anyway.
 
reply
    Bookmark Topic Watch Topic
  • New Topic