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

Hi, Iam a beginner.I need to write a perl script that can call a .exe file (which does conversion from .csv to .xls).Can some one please help me out as to how i can do this. Thank You!

Replies are listed 'Best First'.
Re: Calling .exe file using perl
by Zaxo (Archbishop) on May 29, 2006 at 13:20 UTC

    Aside from system, which was properly recommended, there are several other ways to kick off an executable file. The one you choose depends on what you want the run to do in terms of IPC and process management.

    The system function launches the external program in a new process and waits for it to end before proceeding with the rest of your script. It returns only an exit status.

    The exec function takes off running the new executable in the same process, leaving the rest of your script behind. It never returns unless it failed. It's useful when all you wanted to do in perl was set up some environment variables, or some other kind of initialization. It's also useful after fork.

    Backticks ($out = `foo`;) launch a command and return the captured STDOUT of that command for you to use as you like.

    The open function has a pair of modes, '-|' and '|-', which let you launch a command as if it were a file to read or write. Your file operations serve to read from STDOUT or write to STDIN of the command. When used this way, open returns the pid of the child process.

    There are also a number of modules which deliver different flavors of these. IPC::Run, Open2, and Open3 are three which provide more extensive IPC to system- and open-like commands.

    After Compline,
    Zaxo

Re: Calling .exe file using perl
by prasadbabu (Prior) on May 29, 2006 at 09:45 UTC
Re: Calling .exe file using perl
by roboticus (Chancellor) on May 29, 2006 at 13:44 UTC
    deepa:

    The other esteemed Monks have given you great answers. But I thought that you might like an alternative: There's a great package on CPAN Spreadsheet::WriteExcel that will give you the ability to do a great job in creating spreadsheets in Perl. The example code provided gives you a great starting point.

    I've used that module for several jobs, and always found it to be nice. You can score plenty of points by giving your users a nicely-formatted custom spreadsheet for them. Just something to consider if the .CSV file converter you have doesn't give you enough control over the process....

    --roboticus

      Thanks a lot.That solved my problem
Re: Calling .exe file using perl
by PugSA (Beadle) on May 29, 2006 at 12:10 UTC

    Hi deepa

    The short answer is:

    system("my.exe");

    But the problem with a answer like mine is the old fishing Idiom of 'Give a man (woman) a fish and he'll eat for one day, teach him how to fish and he'll eat for the rest of his life.

    Thus the deserved response from Prasad on where to get the answer. The sooner we learn where to get the answers the esier Perl becomes. O'Reilly Programming Perl or Super Search probably the best places to start.

Re: Calling .exe file using perl
by displeaser (Hermit) on May 29, 2006 at 12:22 UTC
    Hi,

    following the above good advice from fellow Monks, you can get the help directly from your system by typing "perldoc -f system". This will output the help for the function on the command line/shell for you.

    Typing "perldoc perldoc" will give you help on using the perldoc command.

    Hope this helps,
    Displeaser.