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

Hello Monks,

I want to write a script that recives input at runtime... I can do it easily by using <STDIN>..However, problem is i want to create an executable, that asks for some input data.. eg.. Output file etc..

Please suggest..How can i do it?

Thank you

Replies are listed 'Best First'.
Re: Recieving input during runtime..
by cjb (Friar) on Nov 30, 2010 at 10:49 UTC

    You could use Getopt::Long and grab them from the command line? Or you could create a GUI using Tk or Wx. There is nothing wrong with still using <STDIN>.

    How you create a Perl executable on your platform I'll leave to another monk.

    Edited: Added: Tk/Wx references

Re: Recieving input during runtime..
by marto (Cardinal) on Nov 30, 2010 at 10:53 UTC

    Modules such as Getopt::Long provide many features for processing command line arguments if that's what you are looking for.

    "I can do it easily by using <STDIN>..However, problem is i want to create an executable, that asks for some input data"

    Are you saying you can't use <STDIN> from a packaged executable?

      I tried using <STDIN>, however, when i run exe, it doesnt ask me for any input.

      If i run script normally through command prompt it works fine. However according to requirements i need to convert it into an executable.

        Well I tried a very basic example:

        #!/usr/bin/perl use strict; use warnings; print "Please enter an output file name: "; my $outputfile = <STDIN>; chomp($outputfile); print "User input: $outputfile\n";

        and converted it to an executable using pp:

        pp -o inputtest inputtest.pl

        Which runs as follows:

        Please enter an output file name: testfile.txt User input: testfile.txt

        Perhaps if you showed an example of your code and how you converted it to an executable someone would be able to help.

        How are you creating the executable? If you are using something like perl2exe with the -gui option, you won't see anything written to STDERR, for example.
Re: Recieving input during runtime..
by cdarke (Prior) on Nov 30, 2010 at 13:32 UTC
    <STDIN> should work fine. I am guessing, from looking at your previous posts and a few other clues (like your use of 'exe'), the following:
    You are working on Microsoft Windows
    You created a perl executable based on pp or PAR
    When you execute this it does not create a console window

    Are these assumptions correct? How are you running the executable, from Windows Explorer or from a cmd.exe command-line? Do you have any diagnostics you can offer us?

      I am sorry, but i am not using pp to create exe, i could not install pp on my systen becuase i am getting error for 'c compiler'. I tried installing MinGW via ppm and i get error like "no such package". So i used perl2exe... However its giving such problems now..

      I tried command as install MinGW in ppm

      I dont know why it is happening..Is there nything wrong in this command? or there is some other way to install MinGW?

        Which version of ActiveState Perl are you using. Which repositories do you have set up? Are you able to install modules via PPM? Is that ('no such package') the complete message, or is there anything else whe should know?

        Update:

        Show us how you tried to use perl2exe to create the exe. Stop asking us to guess what could be wrong. If you used the -gui option, I'm sure you read the manual:

        "Create a no-console executable. This can be used for Tk and Win32::GUI applications. I/O to STDOUT and STDIN will not be visible. If your application does not work do not use the -gui option while testing as it will hide possible error messages. Applies to Windows version only."

Re: Recieving input during runtime..
by thargas (Deacon) on Nov 30, 2010 at 12:25 UTC

    please show:

    • your code,
    • the commands you used to create the executable

    Without at least that info, we're just guessing.