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

I lack the knowledge on how to resolve a certain problem, if you could even call it a problem... I am helping a friend of mine with some tasks, and short of making a text file and putting in data there, is there any way for me to return data to his program?

Essentially what I need to happen is my friend calls my script with some args, and based on those args, I will get data and print it to console. But is there a way for me to return the actual data to his programvia scalar/array/hash? Will he need to declare a variable that I can fill with data?

Any insight would be awesome! thanks for reading.

EDIT: To add more to this, and just incase there are any questions about this, my friend has a program (exe) on windows. He is using my script for some added functionality. As it stands right now, I output my data to console and he picks it up from there, no problem. What i want to know is, Are there any other ways for my script to return data to his program so i wouldnt need to print to cmd.

Replies are listed 'Best First'.
Re: Returning data to parent program
by Corion (Patriarch) on Nov 12, 2015 at 08:29 UTC

    The easy way would be to use a database like SQLite or to use another kind of temporary file to which your program writes and your friends program reads from. Good formats for structured data would be CSV (Text::CSV_XS) or JSON JSON::XS.

    The best approach is to talk to your friend what format they can read most easily.

Re: Returning data to parent program
by Discipulus (Canon) on Nov 12, 2015 at 08:14 UTC
    Hello james28909,

    the possibility entirely depends on the executable: it accepts input? some program accept input on their STDIN, others ignore it. For example firefox does not accepts inputs:
    perl -e "print 'www.perlmonks.org'"| "C:\Program Files (x86)\Mozilla +Firefox\firefox.exe"
    produce nothing but de default firefox page opened in a new instance of the program.
    grep (i use the win32 port) by other hand, it accepts things in input:
    perl -e "print 'www.perlmonks.org'"| grep w www.perlmonks.org perl -e "print 'www.perlmonks.org'"| grep XXXX
    Some program accept some filename as data file, so you can let your Perl's program write such datafile:
    perl -e "open $fh,'>','perlcreated.txt' or die" && notepad perlcreate +d.txt
    When notepad is called the file yet exists.
    Or the executable can accept data on a specific port, listening on a socket opened on that port, like a webserver...

    There are a lot of possibilities but they all depends on the executable behaviour: it has some ear? or is deaf and dull?

    L*

    UPDATE: note the the term 'parent program' is a little misleading: parent and child parallel is used when a program spwan some other process, possibly with the intention to comunicate eachothers: the program is one but procesess can be many.

    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: Returning data to parent program (popen)
by tye (Sage) on Nov 12, 2015 at 14:33 UTC

    Your Perl code doesn't need to do anything special. The other program just needs to use popen so it can read what your Perl script writes to STDOUT.

    If you want to pass structured data, not just a string, I'd use JSON.

    - tye        

Re: Returning data to parent program
by Anonymous Monk on Nov 12, 2015 at 08:06 UTC

    What i want to know is, Are there any other ways for my script to return data to his program so i wouldnt need to print to cmd.

    See perlipc.

    You get special file handles STDIN/STDOUT/STDERR

    Then there is regular files, and sockets

    Those are your basic/common/standard choices

    Use JSON as data exchange format.

Re: Returning data to parent program
by james28909 (Deacon) on Nov 13, 2015 at 19:25 UTC
    sorry gals/guys, i have not had a good chance to come back and comment yet. i will soon though.