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

Hi all, I am trying to create a new build in jenkins through perl, but after writing the below code and run it, its asking "Enter passphrase for C:\Users\saishett\.ssh\id_rsa: " and after giving the pass phrase its expecting xml content as a input. please find the below code.

my @args = ('java -jar jenkins-cli.jar -s http://localhost:8080/ creat +e-view abcd'); system(@args) == 0 or die "\n system @args failed: $?";
If i run the jenkkins-cli  using cmd then after giving passphrase i paste the xml file-- then the view gets created.
My question is " How to give the xml as an input(STDIN) after running the perl script as it expects ONLY XML file? "

Replies are listed 'Best First'.
Re: How to give content of an xml file as a STDIN through PERL
by Eily (Monsignor) on Apr 03, 2015 at 09:45 UTC

    You can open a pipe to your other process like a file handle:

    # Open the handle open my $handle, '|-', 'java -jar jenkins-cli.jar -s http://localhost: +8080/ create-view abcd' or die "Couldn't open pipe: $!"; # Use it like a file print $handle "Hello"; # Will print "Hello" to the standard input of t +he java process
    This means that the pass phrase will also have to be written through perl, something like this should work: print $handle scalar <STDIN>; # print to handle one line from the console

    You should have a look at open and perlipc for more information on handles and inter-process communications.

Re: How to give content of an xml file as a STDIN through PERL
by Anonymous Monk on Apr 03, 2015 at 09:42 UTC

    See IPC::Run3

    Also, I'd look for a jenkins option to pass filename instead of data

      Thank you, I found the way to pass filename:
      my @args = ('java -jar jenkins-cli.jar -s http://localhost:8080/ creat +e-job job_name < "path to xml file" '); system(@args) == 0 or die "\n system @args failed: $?";