Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??

I am attempting to set up a program that will perform a set of user defined steps. Each step will be a seperate program, which could be anything (e.g. shell script, unix command, c++ program, perl program). My program will execute the specified command and check the return code. If the return code is 0, my program will move onto the next user defined step.

Here is my problem, any one of the specified steps could be a program that needs input from the user. What I want to do is have my program turn over control to the executed program (allowing the user to specify any necessary termial input) and return control back to me when it finishes. All I need from this is the return code of the executed process.

I've tried just using system() call, but that won't get STDIN from the user.

Any ideas?

Here is my program so far (

#!/usr/bin/perl $scriptName = ''; $logFileName = ''; $numberOfSteps = ''; $restart = 'Y'; @step = (); $error = 0; foreach $_ (@configFile) { next if ($_ =~ /^\s*$/); next if ($_ =~ /^\s*#/); chop(); if ($_ =~ /^\s*ScriptName:\s+\S+\s*$/) { ($tag,$scriptName) = split(); } elsif ($_ =~ /^\s*LogFileName:\s+\S+\s*$/) { ($tag,$logFileName) = split(); } elsif ($_ =~ /^\s*NumberOfSteps:\s+[0-9]+\s*$/) { ($tag,$numberOfSteps) = split(); } elsif ($_ =~ /\s*Restart:\s+\S+\s*$/) { ($tag,$restart) = split(); } elsif ($_ =~ /^\s*Step\s+[0-9]:/) { $stepNum = $_; $stepNum =~ s/^\s*Step\s+([0-9]+):.*$/$1/; $command = $_; $command =~ s/^\s*Step [0-9]:+\s+//; $step[$stepNum] = $command; } else { print STDERR "Error: unknown config file line:\n"; print STDERR " $_\n"; $error = 1; } } for ($i=1;$i<=$numberOfSteps;$i++) { print "$i: $step[$i]\n"; $ret = system($step[$i]); if ($ret) { print STDERR "\nError: last step failed.\n"; exit(1); } }

Here is a sample script to call this program

#!/bin/ksh << ! ScriptName: testScript LogFileName: boing NumberOfSteps: 4 Restart: N Step 2: ls -l Step 1: $HOME/bin/gettime Step 4: ps -elf | grep wam Step 3: /tmp/thing !

Here is the /tmp/thing script that asks for input

#!/bin/ksh print "This is the output." print "You need to enter a value: " read ans print "You entered the value of $ans." exit 1

When it runs the /tmp/thing script I am not given the chance to enter the requested input

In reply to How to "transfer control" to child process? by VingInMedina

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.