Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

system function problem: help

Status
Not open for further replies.

Graziella

Programmer
Jul 8, 2004
38
AT
Hi,

I am working on my PC running Windows XP
I have these few lines of code:

$dir = "c:/Program\ Files/eclipse/eclipse/workspace/ura";
print "DIR: $dir\n";
$cmd = "$dir/etc/run.bat $dir/build/edu/umd/simfinder/Eval ";
system($cmd);

I am trying to write a script that calls java classes to be able to run an experiment.
When I exectute the above few lines of code:
the printing statement shows that $dir is defined with the path I wanted.
However, the system function does not work and the warning I get it:
Can't exec "c:program"
which tells me that when I call system, not the entire value of $dir is passed, but somehow only "c:program" is and of course that path does not exists.

Please help me.

Grazia
 
Take out the backslash before the space in `Program Files'.
 
You will need to quote the string twice.
Try this:
Code:
$cmd = "\"$dir/etc/run.bat\" \"$dir/build/edu/umd/simfinder/Eval\" ";

The command is being split on the space in "Program Files".

Trojan.

 
TrojanWarBlade is right.
But I'd suggest the qq() function to avoid the backslashed quotes.
Code:
$cmd = [b]qq([/b]"$dir/etc/run.bat" "$dir/build/edu/umd/simfinder/Eval"[b])[/b];

HTH




 
LOL

good shooting mikevh. I couldn't agree more.
It looks so much cleaner like that. :)


Trojan.

 
Now, similar problem:
@eval = `cd $dir_eval; ls *eval* | grep eval`;

would work in a regular Unix system, but with my Windows XP it is not:
@eval gets as value the stuff to teh right of = !

Maddening, the qq() do not work in this case ...

Grazia
 
Guys, we have not solved the problem or I jsut messed up with your suggestions:

Code:
$dir = qq("c:/Program\ Files/eclipse/eclipse/workspace");
$cmd = "perl qq($dir/paraphrase-corpora/bin/getPrecisionRecall.pl) qq($dir_eval/$file) qq($dir/eclipse/workspace/paraphrase-corpora/simfinder/mySimFinderCorpus/TRAIN_DEV_TEST/trainingdata-dev20.txt)";
	system($cmd);
 
When you use paths on windows with perl it better to escape your backslashes with backslashes. This way you will not trouble yourself. I don't think that you are trying to right something portable, do you ?
so you first code should look like this.
Code:
$dir = "c:\\Program Files\\eclipse\\eclipse\\workspace\\ura";
print "DIR: $dir\n";
$cmd = "$dir\\etc\\run.bat $dir\\build\\edu\\umd\\simfinder\\Eval";
system($cmd);

Now what is the problem that have not solved?


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
Grazia

You can use perl to get the same behaviour as
Code:
@eval = `cd $dir_eval; ls *eval* | grep eval`;
with
Code:
use strict;
use warnings;

my $dir_eval = [red]"C:\\Visual Studio Projects";[/red]  
opendir(EVAL, $dir_eval) or die "Can't open $dir_eval";
my @files = grep {/[red]dev[/red]/i} readdir(EVAL);
closedir(EVAL);

print join("\n", @files);
Just change the bits in red to your directory and your search string. This also avoids shelling out to another three commands.
 
This is how I solved it.

I called my script with
Code:
perl launchEval.pl 'c:/Program\ Files/eclipse/eclipse/workspace/ura'

and inside my script I have:

Code:
$cmd = "perl 'c:/Program\ Files/eclipse/eclipse/workspace/paraphrase-corpora/bin/getPrecisionRecall.pl' 'c:/Program\ Files/eclipse/eclipse/workspace/ura/$file' 'c:/Program\ Files/eclipse/eclipse/workspace/paraphrase-corpora/simfinder/mySimFinderCorpus/TRAIN_DEV_TEST/trainingdata-dev20.txt'";

Notice the ' '.
I guess it is Windows XP and cigwyn together ...

Grazia
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top