Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

How Do I Get Batch Input to Work in DOS?

by jmk2012 (Initiate)
on Mar 01, 2012 at 01:45 UTC ( [id://957067]=perlquestion: print w/replies, xml ) Need Help??

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

I have a perl script which asks routine questions for input. Rather than do manual input, I'd like to put the answers in a file and use some kind of re-direction to feed input to the script. I tried 'myfile.pl < pl_input.txt' where '<' is the input operator in DOS. But it doesn't work as expected with my perl script. Advice? Any help appreciated.
  • Comment on How Do I Get Batch Input to Work in DOS?

Replies are listed 'Best First'.
Re: How Do I Get Batch Input to Work in DOS?
by BrowserUk (Patriarch) on Mar 01, 2012 at 02:49 UTC
    I tried 'myfile.pl < pl_input.txt' .... But it doesn't work ...

    Works fine for me:

    C:\test>junk.pl < junk.pl >< elihw _$ esrever ralacs tnirp C:\test>

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      The fact it works for you makes me wonder what configuration settings or other special constructs might be needed for this to work on my computer. Are there any environment variables that might need tweaking? Or anything to put in the script file? tnx, jmk
        Are there any environment variables that might need tweaking? Or anything to put in the script file?

        How about you provide a little more information:

        1. What version of perl are you using?

          perl -v

        2. What version of "DOS" are you using? ver
        3. What file associations do you have? assoc .pl

          The above produce output like: .pl=xxxx. Substitute whatever you get instead of 'xxxx' into the following command: ftype xxxx

        4. The output from the following two commands:
          set pat set per
        5. Your full runnable code.

          Or if it is huge or proprietary; a complete, self-contained, runnable script that demonstrates the problem.

        6. A cut&paste of the console log showing the posted code being run on your system.

        If you supply that information, we here will almost certainly be able to solve your problem. Without it, all we can do is guess, usually wrongly.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The start of some sanity?

Re: How Do I Get Batch Input to Work in DOS?
by Corion (Patriarch) on Mar 01, 2012 at 08:48 UTC
Re: How Do I Get Batch Input to Work in DOS?
by ww (Archbishop) on Mar 01, 2012 at 02:38 UTC
    How about writing a routine into your myfile.pl to read input.txt into an array, and then feeding the (input) elements as needed/where needed?

    But heed Riales: this would be better advice (less of a WAG) were you to post some code showing what's at issue. You'll do better, also, if you tell us something more specific than "doesn't work as expected." That could mean anything from 'no visible response' to 'my computer starts spitting out $20 gold pieces.'

Re: How Do I Get Batch Input to Work in DOS?
by Riales (Hermit) on Mar 01, 2012 at 01:57 UTC

    I'm not familiar with DOS, but I would think you need to actually print the contents of pl_input.txt to STDOUT before piping it into your program. This is how I would do it in bash:

    $ cat pl_input.txt | myfile.pl

    EDIT: Nevermind, I did some research and it looks like what you were doing should be fine. Maybe post your code/input file so we have some more to go on? What's happening that's unexpected?

      Thanks for the response. Here are some more details - The script is a format checker (aka linter) for script input - to ensure against typos. You provide the directory where the files are located, indicate the exam you want performed and the script generates a report of any errors found. If you want to retest- well, an input file of commands would be helpful, thus my question. Here's the code snippet that receives the input.
      if( $runnum < 1) { $cwd = Win32::GetCwd(); $prgmdir = $cwd; # $prgmpth = "$prgmdir\\"; print "\nProgram thinks it is located in the following directo +ry:\n"; print "\t$cwd\n"; print "if incorrect (PATH has spaces)! Enter full path or ret +urn\n\n"; chomp ($prgmd = <STDIN>); if( $prgmd =~ /^([a-zA-Z];\\).+$/ ) { $prgmdir = $prgmd; } else { $prgmdir = $cwd; } $prgmdir =~ /^(\w:).*/; $prgmdrv = $1 . ":"; }
      When I run the script, I get the above query which seems to get some input (but nothing obvious on screen) where it next goes to the menu containing the "exit" command and then goes to the dos prompt as if it concluded. A check of the output directory indicates no activity. I expected to see some material to the screen and/or results in the work directory - but this is not the case, thus the question on what it would take to get it to work. jmk

        When you run your script, do you get those lines about where the program thinks it is and if it's incorrect to enter the full path or return? Have you tried adding a print after you assign to $prgmdrv to see what it's doing at that point? (Standard 'print statements everywhere!' advice, but still...)

        I wonder if it might make more sense to modify the original script to optionally take an input file of commands instead of trying to pipe the commands in externally?

Re: How Do I Get Batch Input to Work in DOS?
by jmk2012 (Initiate) on Mar 01, 2012 at 20:07 UTC
    Thanks for the response. Here are some more details - The script is a format checker (aka linter) for script input - to ensure against typos. You provide the directory where the files are located, indicate the exam you want performed and the script generates a report of any errors found. If you want to retest- well, an input file of commands would be helpful, thus my question. Here's the code snippet that receives the input.
    if( $runnum < 1) { $cwd = Win32::GetCwd(); $prgmdir = $cwd; # $prgmpth = "$prgmdir\\"; print "\nProgram thinks it is located in the following directo +ry:\n"; print "\t$cwd\n"; print "if incorrect (PATH has spaces)! Enter full path or ret +urn\n\n"; chomp ($prgmd = <STDIN>); if( $prgmd =~ /^([a-zA-Z];\\).+$/ ) { $prgmdir = $prgmd; } else { $prgmdir = $cwd; } $prgmdir =~ /^(\w:).*/; $prgmdrv = $1 . ":"; }
    download When I run the script, I get the above query which seems to get some input (but nothing obvious on screen) where it next goes to the menu containing the "exit" command and then goes to the dos prompt as if it concluded. A check of the output directory indicates no activity. I expected to see some material to the screen and/or results in the work directory - but this is not the case, thus the question on what it would take to get it to work. jmk

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-23 20:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found