Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
No such thing as a small change
 
PerlMonks  

Use a perl variable on a command that prompts for input

by andyarp (Initiate)
on Oct 18, 2013 at 03:37 UTC ( #1058699=perlquestion: print w/ replies, xml ) Need Help??
andyarp has asked for the wisdom of the Perl Monks concerning the following question:

So, i'm trying to use perl to write a script to automate a process that controls bitlocker drive encryption pins. I've written a script that takes the computername (format xxxx-xxxxxxxxxx) and takes the last 4 digits of the name and inputs those digits to a variable ($pin). Then, it runs command

system "manage-bde -changepin C: -computername $asset";

It then pops up asking what you want the pin to set to. My question is, how can i take the 4 digit number in the variable $pin i mentioned and have perl automatically type them into the prompt that manage-bde pops up with?

Comment on Use a perl variable on a command that prompts for input
Download Code
Re: Use a perl variable on a command that prompts for input
by Anonymous Monk on Oct 18, 2013 at 04:06 UTC
Re: Use a perl variable on a command that prompts for input
by kcott (Abbot) on Oct 18, 2013 at 07:17 UTC

    G'day andyarp,

    Welcome to the monastery.

    I'm unfamiliar with manage-bde. When you said "It then pops up asking ...", I thought it sounded like a GUI; however, in the next sentence, you write "... automatically type them into the prompt ...", which sounds less like a GUI, and more like 'enter a value when prompted'. Some clarification on this would help.

    There's potentially a few ways you could do this. Here's some examples:

    -- Ken

      In addition to Ken's three options here, there is also the possibility of using echo inside the system command as in:

      system ("echo my_input | some_command arg arg arg");

      The advantages I find in this are that it is simple and can easily be tested in the shell before embedding it in your Perl script.

      The downside is mostly a lack of portability but also perhaps consideration of properly escaping my_input to cope with the possible shell expansions.

        I'm looking into all these options. Yes it is a message that comes up in the command prompt area. I'm going to give this echo command a try. It sounds like it may work

        I tried the "Echo" option, but i kept getting "the handle is invalid", so i think it may be a no-go.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2014-04-20 03:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls