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

Hi All, Is there a way to pass values to unix app and get results from the app? I don't know how to paste a screenshot of what i am working? Please let me know, how to pass values and get results from the unix app. the app displays the results on the screen, i am not sure how to get those values and pass values. The app gives options to select and i want to pass values accordingly to select the options. Please assist. Is there a way i could do this. I am using an tool provided by CA Siteminder, which is called XPSExplorer. This app gives output to select options, in short, it pretty much like a human interface. All i want to do is to automate this tool, by calling the tool through perl and create a app. Is it possible to pass values to this app and retrieve the results form this app.
  • Comment on passing values from perl to unix app and getting result from the app

Replies are listed 'Best First'.
Re: passing values from perl to unix app and getting result from the app
by salva (Canon) on Jun 05, 2014 at 11:36 UTC
      Hi Salva,

      I know, there is document for Perl API, but that document doesn't have an API on what i am working nor does CA. Only option i have is to call the CA tool inbuilt with the Application.

Re: passing values from perl to unix app and getting result from the app
by marto (Cardinal) on Jun 05, 2014 at 10:31 UTC
Re: passing values from perl to unix app and getting result from the app
by LanX (Saint) on Jun 05, 2014 at 10:33 UTC
    What kind of UNIX app?

    Do you have control about the code (like a bash script) or do you need to mimic a human interface?

    Cheers Rolf

    (addicted to the Perl Programming Language)

      Trying to mimic a human interface. I have updated my question with more details, if that could help.

        I'm pretty sure this application has a man-page explaining how to interface it.

        Read it and ask the right questions please!

        Sorry, doing it for you is off topic, this is not a board for UNIX basics and obscure tools.

        Maybe better ask your sysadmin for help.

        And please add code tags, your update is not readable.

        Cheers Rolf

        (addicted to the Perl Programming Language)

        I've already given you a link to read and understand, please do so and fix the formatting of your post.

        A reply falls below the community's threshold of quality. You may see it by logging in.
Re: passing values from perl to unix app and getting result from the app
by zentara (Cardinal) on Jun 05, 2014 at 14:44 UTC
    Is there a way to pass values to unix app and get results from the app?

    My first thought is to use IPC:Open3

    A simple example:

    #!/usr/bin/perl use warnings; use strict; use IPC::Open3; #interface to "units" calculator #my $pid = open3(\*WRITE, \*READ, \*ERROR,"units -t"); #terse output my $pid = open3(\*WRITE, \*READ, 0 , "units -t"); #if \*ERROR is set to 0, STDERR is sent to STDOUT #chomp(my $prompt = <READ>); #print "$prompt\n"; foreach ( '100 yards', '1 mile', '1 kilometer', '1 parsec', '1 foobar' +){ print WRITE "$_\n meters \n"; chomp(my $answer = <READ>); print "$_ = $answer meters\n"; } __END__

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      Don't bother! :)

      He shortly revealed (and deleted the update later again) that its about a CA tool and salva already gave him a link to the Perl API.

      Cheers Rolf

      (addicted to the Perl Programming Language)

Re: passing values from perl to unix app and getting result from the app
by Lennotoecom (Pilgrim) on Jun 05, 2014 at 11:21 UTC
    $a = 'perlmonks.org'; @b = `ping $a -c 3`; print "@b\n";
    but it doesn't do this part of your task:
    "The app gives options to select and i want to pass values accordingly to select the options."
Re: passing values from perl to unix app and getting result from the app
by Anonymous Monk on Jun 05, 2014 at 11:30 UTC
Re: passing values from perl to unix app and getting result from the app
by taint (Chaplain) on Jun 05, 2014 at 14:12 UTC
    Greetings, ChristieJS.

    As others have duly noted, above. You really need to provide more specifics, to get anything remotely helpful, in answer to your question. Without those details, it's all quesswork, on our part. Which leaves us as frustrated, as you probably feel.

    That said; generally speaking. It can be something similar to the following

    my $arg1 = ('-switcha . -switchb l -switchc'); my $arg2 = ('+15'); my $arg3 = ('filename argument'); system("/path/to/command $arg1 $arg2 | $arg3");
    as you can see. The above only illustrates the semantics. Which is probably of little help with the problem you are currently wrestling with. So without further details form you. This is probably the best you'll get.

    The question you ask, is already answered in the Tutorials, and more specifically, elsewhere in the Online Perl Documentation. As well as locally, on your computer (perdoc).

    Best wishes.

    --Chris

    ¡λɐp ʇɑəɹ⅁ ɐ əʌɐɥ puɐ ʻꜱdləɥ ꜱᴉɥʇ ədoH

      Thanks Chris(taint). I guess this should work.

      Let me explain a bit. There is a tool which comes along with CA application. And that application has more than 100 options to choose from, and i am trying to automate that without even seeing the options on the screen. And that tool is called XPSExplorer. Below is the code on what i working on.

      I have created a .txt file and run the code as below

      perl callxps.pl input.txt
      use warnings; use strict; use ARGV::readonly; use Netegrity::PolicyMgtAPI; system(XPSExplorer); while (<>) { print; }

      But what happens is that it doesn't pass the value in the text file to the command line, rather when i quit, it prints the value

        Hello, ChristieJS.

        If I understand you correctly. You're working with callxps.pl, which is the XPSExplorer application/initiator, and attempting to pass input.txt, as argument(s) to that file.

        If so, the problem (I suspect) is. That callxps.pl wasn't designed that way. If you were on a *NIX based box. You might be able to make use of "redirection" -- (callxps.pl < input.txt). But, I suspect, a bit of a long-shot.

        Even if redirection worked. You're still going to need the keys. So that you can create key / value pairs. eg;

        # assuming name, password are keys my $name = qw(ChristieJS); my $password = qw(SuperSecret); # or name = ChristieJS password = SuperSecret # or name: ChristieJS password: SuperSecret
        and how to best pass those, largely depends on the format expected from callxps.pl. You might even be able to pass input.txt as
        perl callxps.pl & input.txt
        again, a bit of a stretch.

        Honestly, as should be pretty apparent by now, I'm groping. We still don't have enough details to effectively provide a reasonable solution.

        You might be able to find the keys in callxps.pl, and create a wrapper, that calls callxps.pl, passing the key values to callxps.pl. This, I think, for your situation, would be the best choice. But in the end. Without those keys. Providing a more specific answer/solution, is pretty much, a futile endevour.

        Now that you have a better idea of exactly what's required, perhaps you can figure it out. Or provide better details, so we might be better prepared to answer.

        --Chris

        ¡λɐp ʇɑəɹ⅁ ɐ əʌɐɥ puɐ ʻꜱdləɥ ꜱᴉɥʇ ədoH

Re: passing values from perl to unix app and getting result from the app # Crosspost!
by LanX (Saint) on Jun 06, 2014 at 14:55 UTC