How to resolve parameter read from text file in perl script

Discussion in 'Perl Misc' started by Gancy, Feb 9, 2005.

  1. Gancy

    Gancy Guest

    Hi All,
    I have a perl script which reads parameters from text file and builds
    the command line string for another perl script. and i intend to
    execute the same with systm command.

    parameter file would look Something like this

    Parameter file:
    description=1
    log=0
    outputdir=~gancy/testsource
    scandir=pwd

    perl script reads this and builds commnad line and calls the system
    command.

    if i print the string would look like
    print $CmdLine;

    perl BinaryParser.pl -d ~gancy/testsource pwd

    system("$CmdLine");

    but the problem is system command does not resolve ~ and pwd.

    I have tried same in C, it works exactly as i want. Even i tried to
    fork antoher process.

    any suggestions

    Thanks
    Ganesh Tiwari
     
    Gancy, Feb 9, 2005
    #1
    1. Advertising

  2. Gancy wrote:
    > I have a perl script which reads parameters from text file and builds
    > the command line string for another perl script. and i intend to
    > execute the same with systm command.


    <snip>

    > print $CmdLine;
    >
    > perl BinaryParser.pl -d ~gancy/testsource pwd
    >
    > system("$CmdLine");
    >
    > but the problem is system command does not resolve ~ and pwd.


    Why are you using system() to invoke another Perl script? Why not

    @ARGV = qw(-d ~gancy/testsource pwd);
    do 'BinaryParser.pl';

    or to also check for errors

    defined do 'BinaryParser.pl' or die $!;

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Feb 9, 2005
    #2
    1. Advertising

  3. Gancy

    Guest

    Gunnar Hjalmarsson wrote:
    > Gancy wrote:
    > > system("$CmdLine");
    > >
    > > but the problem is system command does not resolve ~ and pwd.

    >
    > Why are you using system() to invoke another Perl script?


    He is using it to resolve ~.
     
    , Feb 9, 2005
    #3
  4. Gancy

    Guest

    Gancy wrote:

    > if i print the string would look like
    > print $CmdLine;
    >
    > perl BinaryParser.pl -d ~gancy/testsource pwd
    >
    > system("$CmdLine");
    >
    > but the problem is system command does not resolve ~ and pwd.


    What do you mean by 'resolve pwd'? The string 'pwd' does not contain
    any shell metacharacters.

    > I have tried same in C, it works exactly as i want.


    Works here for me with perl5.6.1 and 5.8.5 on Linux.

    What's your perl -V ?

    Have you read 'perldoc -q tilde' ?
     
    , Feb 9, 2005
    #4
  5. wrote:
    > Gunnar Hjalmarsson wrote:
    >> Gancy wrote:
    >>> system("$CmdLine");
    >>>
    >>> but the problem is system command does not resolve ~ and pwd.

    >>
    >> Why are you using system() to invoke another Perl script?

    >
    > He is using it to resolve ~.


    Aha, thanks!

    So, a new attempt at a pure Perl solution:

    use FindBin '$Bin';
    @ARGV = qw(-d ~gancy/testsource pwd);
    map { s#~#/home/#; s/pwd/$Bin/ } @ARGV;
    do 'BinaryParser.pl';

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Feb 9, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dpackwood
    Replies:
    3
    Views:
    1,829
  2. ScriptNFool
    Replies:
    0
    Views:
    407
    ScriptNFool
    Jun 30, 2003
  3. Replies:
    1
    Views:
    10,254
  4. Noah Roberts

    unable to resolve template parameter

    Noah Roberts, Dec 2, 2009, in forum: C++
    Replies:
    6
    Views:
    491
    Triple-DES
    Dec 8, 2009
  5. Mmcolli00 Mom
    Replies:
    2
    Views:
    201
    Mmcolli00 Mom
    Jan 27, 2009
Loading...

Share This Page