How to resolve parameter read from text file in perl script

G

Gancy

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
 
G

Gunnar Hjalmarsson

Gancy said:
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.

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 $!;
 
N

nobull

Gancy said:
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' ?
 
G

Gunnar Hjalmarsson

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';
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top