Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

launching external process macOS

by Anonymous Monk
on May 20, 2018 at 17:36 UTC ( [id://1214947]=perlquestion: print w/replies, xml ) Need Help??

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

I am quite new to using Perl on a macOS, so be patient.

On Windows I usually launch external processes from the Shell using "system". For example to run "pdftotxt.exe" I use the following:

system ("pdftotext", "-enc", "UTF-8", "myPDF.pdf","myTXT.txt");

Which is the best way to achieve the same in a script for macOS?

Replies are listed 'Best First'.
Re: launching external process macOS
by haukex (Archbishop) on May 20, 2018 at 17:44 UTC
    On Windows I usually launch external processes from the Shell using "system". ... Which is the best way to achieve the same in a script for macOS?

    In theory it should be exactly the same (except for the .exe extension of course), system is cross-platform (with a few caveats, see system in perlport). Have you tried it, are you having any problems? If so, please post the exact error message along with a short piece of code needed to reproduce the error (an SSCCE).

    BTW, you should check the return value of system for errors; it is also reflected in $? (but only rely on its value immediately after the call). I wrote at length about the topic of running external commands here.

      Thank you very much. I'll first read your valuable post (also for checking the return value, which I didn't do :( )

Re: launching external process macOS
by kcott (Archbishop) on May 21, 2018 at 10:57 UTC

    I've been using Perl on macOS (and previously, Mac OS X) for quite a few years; however, I don't have it in front of me now so I can't show examples.

    ++haukex is quite correct. system works as documented (i.e. system LIST) on macOS.

    Beyond corroborating that, I did want to provide some advice regarding:

    "I am quite new to using Perl on a macOS"

    The version of Perl provided by Apple, often referred to as the System Perl, and found in /usr/bin/perl, should generally be avoided outside of specific system use. This Perl is provided for use by macOS, is often some versions behind the current stable one, and may contain its own specific patches. Installing what appears to be a quite innocent CPAN module, may upgrade a dependency, and potentially cause problems with macOS itself. When Apple upgrades macOS, its Perl may also be upgraded (let's say from 5.X to 5.Y): when this happens, everything under 5.X is completely removed, including all CPAN and personal modules you may have installed.

    I'd strongly recommend you install perlbrew (see App::perlbrew). I've been using this for years, as have many others here, without any problems. If you do have any issues, there's plenty of people here who can help you.

    — Ken

      Thank you for both answers. I switched to Perlbrew, and it works like a charm. The same is for "system".

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1214947]
Approved by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-03-29 12:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found