views:

414

answers:

3

I have a Perl/POE/Tk script running on Win32 ActivePerl that calls executables using system. I created an exe of the script using pp. I can unpack the exe and see the executables off the root of the "zip" file directory, but when I run the exe and try to use the functionality of the system calls I get a "file not found" type of error;

'..\cpau' is not recognized as an internal or external command, 
operable program or batch file.

cpau.exe is one of the included files.

pp is called thus:

pp -i alias3.ico -g -a add_event.job -a add_rec.job -a CPAU.exe -a del_event.job -a del_rec.job -a dnscmd.exe -a eventcreate.exe -o alias_v_3-0.exe alias_poe_V-3_0_par.pl

I am guessing that I need to adjust the path of the system calls. I currently am trying to use the default path;

system("cpau -dec -file add_rec.job -nowarn -wait");

I tried this:

system("..\cpau -dec -file ..\add_rec.job -nowarn -wait");

reasoning that pp put the script in the \scripts\ directory, but no joy. Any suggestions?

+3  A: 

Update: My suggestions below do not work. However, I am going to leave them up in case someone else has a similar question. This answer shows a lot of things that may sound reasonable but do not work.

See the discussion following the OP's repost for code using $ENV{PAR_TEMP} that solves the OP's problem

FOR REFERENCE

pp docs say:

-a, --addfile=FILE|DIR ...

By default, files are placed under / inside the package with their original names.

By using system, you are asking cmd.exe to find the file and I now realize that probably is a losing battle unless you have a separate executable called cpau.exe. I do not have time to try this right now, but a you might have to do the fork and exec yourself instead of relying on system. As in:

exec 'CPAU.exe', @args

Previous answer:

The string you pass to system does not contain what you think it does:

use strict;
use warnings;

my $x= "..\cpau -dec -file ..\add_rec.job -nowarn -wait";

print $x, "\n";
__END__

C:\Temp> fgh
..►au -dec -file ..dd_rec.job -nowarn -wait

Use (edited following OP's comment below):

system "..\\cpau -dec -file ../add_rec.job -nowarn -wait";

I would also recommend using the list form of system:

system '..\\cpau', qw(-dec -file ../add_rec.job -nowarn -wait);

In addition, you might find FindBin handy if you want to specify the path to cpau relative to the current script's directory.

For example:

#!/usr/bin/perl

use strict;
use warnings;

use FindBin qw($Bin);
use File::Spec::Functions qw( catfile );

my $program = catfile $Bin, '..', 'cpau';

system $program, qw(-dec -file ../add_rec.job -nowarn -wait);

__END__
Sinan Ünür
Or `"..\\.."` or `'..\..'` if the command is broken and handles / specially (as opposed to just passing them through to the Win32 API, which globally understands both / and \ as path delimiters).
ephemient
Tried system '../cpau', qw(-dec -file ../add_rec.job -nowarn -wait);Got back;'..' is not recognized as an internal or external command,operable program or batch file.
jpolache
system '.\\cpau', qw(-dec -file .\\add_rec.job -nowarn -wait);works if directory where the exe is has the other files already in it, but not if the exe is in a directory by itself.
jpolache
@jpolache Updated my answer in light of your comments above.
Sinan Ünür
Added recommended code. Ran pp-created exe from an empty directory. Error message as follows;'C:\cpau' is not recognized as an internal or external command,operable program or batch file.
jpolache
A: 

I realized that a another call to an executable in the code was working. I looked and found that the call that was working used backtics rather than a system()call. I changed the other calls to backtics and the problem went away.

`.\\cpau -dec -file .\\del_rec.job -nowarn -wait`;

So, this fixes the problem, buy why? What is the difference between system() and a backtic in the win32 shell?

Spoke too soon. This works in a directory where cpau already exists. When I tried it in c:\temp I got the "'cpau' is not recognized as an internal or external command, operable program or batch file." error. Very frustrating.

I'm stumped.

`cpau -dec -file del_rec.job -nowarn -wait`;

I tried it with and without the leanding ".\\". Same error either way.

jpolache
+2  A: 

See the ultimate soultion in the post "Where does pp (PAR) unpack add (-a) files?"

jpolache