| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Alien::BatToExeConverter; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Alien::BatToExeConverter - Convert a DOS Batch Script to an Executable |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Convert a batch script to an executable that won't show a DOS box |
|
12
|
|
|
|
|
|
|
Alien::BatToExeConverter::bat2exe( |
|
13
|
|
|
|
|
|
|
bat => 'C:\strawberry\perl\bin\foo.bat', |
|
14
|
|
|
|
|
|
|
exe => 'C:\strawberry\perl\bin\foo.exe', |
|
15
|
|
|
|
|
|
|
); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
F is a nice little Windows Freeware program, |
|
20
|
|
|
|
|
|
|
built from open source elements, that will take a batch script and |
|
21
|
|
|
|
|
|
|
convert it into an executable (both as a command-line form, and as a |
|
22
|
|
|
|
|
|
|
GUI form). |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
|
27
|
|
|
|
|
|
|
|
|
28
|
2
|
|
|
2
|
|
28502
|
use 5.008; |
|
|
2
|
|
|
|
|
8
|
|
|
|
2
|
|
|
|
|
99
|
|
|
29
|
2
|
|
|
2
|
|
13
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
86
|
|
|
30
|
2
|
|
|
2
|
|
27
|
use warnings; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
75
|
|
|
31
|
2
|
|
|
2
|
|
11
|
use Carp (); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
43
|
|
|
32
|
2
|
|
|
2
|
|
1747
|
use File::Which (); |
|
|
2
|
|
|
|
|
2294
|
|
|
|
2
|
|
|
|
|
39
|
|
|
33
|
2
|
|
|
2
|
|
1774
|
use File::ShareDir (); |
|
|
2
|
|
|
|
|
15005
|
|
|
|
2
|
|
|
|
|
41
|
|
|
34
|
2
|
|
|
2
|
|
1978
|
use IPC::Run3 (); |
|
|
2
|
|
|
|
|
98396
|
|
|
|
2
|
|
|
|
|
730
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=pod |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 bat2exe_path |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
The C function is used to locate the F |
|
43
|
|
|
|
|
|
|
tool on the host. The Alien module will look in the local binary search |
|
44
|
|
|
|
|
|
|
path, and then if a local version can't be found, it will instead return |
|
45
|
|
|
|
|
|
|
the path to a bundled version. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub bat2exe_path { |
|
50
|
|
|
|
|
|
|
# Check for the installed version |
|
51
|
1
|
|
|
1
|
1
|
16
|
my $installed = File::Which::which('Bat_To_Exe_Converter'); |
|
52
|
1
|
50
|
|
|
|
286
|
return $installed if $installed; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Default to the bundled version |
|
55
|
1
|
|
|
|
|
9
|
File::ShareDir::dist_file( |
|
56
|
|
|
|
|
|
|
'Alien-BatToExeConverter', |
|
57
|
|
|
|
|
|
|
'Bat_To_Exe_Converter.exe', |
|
58
|
|
|
|
|
|
|
); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=pod |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 bat2exe |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Convert a batch script to an executable that will have an icon, |
|
66
|
|
|
|
|
|
|
# won't show a DOS box, and will suppress to the command line. |
|
67
|
|
|
|
|
|
|
Alien::BatToExeConverter::bat2exe( |
|
68
|
|
|
|
|
|
|
bat => 'C:\strawberry\perl\bin\foo.bat', |
|
69
|
|
|
|
|
|
|
exe => 'C:\strawberry\perl\bin\foo.exe', |
|
70
|
|
|
|
|
|
|
ico => 'C:\strawberry\perl\bin\foo.ico', |
|
71
|
|
|
|
|
|
|
dos => 0, |
|
72
|
|
|
|
|
|
|
); |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
The C function is used to execute F and |
|
75
|
|
|
|
|
|
|
generate an executable from the batch script. It takes a series of named |
|
76
|
|
|
|
|
|
|
params, returning true on success or throwing an exception on failure. |
|
77
|
|
|
|
|
|
|
The default settings are intended to produce an .exe script for launching |
|
78
|
|
|
|
|
|
|
a GUI application. |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
The compulsory C param should be the name of the source batch script. |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
The compulsory C param should be the path to white the executable to, |
|
83
|
|
|
|
|
|
|
and must NOT already exist. |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
The optional C param will bind an icon to the executable. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
The optional C param will indicate that the executable is intended |
|
88
|
|
|
|
|
|
|
for the command line. If C supplied, STDOUT and STDERR will be |
|
89
|
|
|
|
|
|
|
supressed and a "DOS box" will not be shown on execution. |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub bat2exe { |
|
94
|
0
|
|
|
0
|
1
|
|
my %param = @_; |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# Required input batch script |
|
97
|
0
|
|
|
|
|
|
my $bat = $param{bat}; |
|
98
|
0
|
0
|
0
|
|
|
|
unless ( $bat and $bat =~ /\.bat$/ and -f $bat ) { |
|
|
|
|
0
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
Carp::croak("Missing or invalid bat file"); |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# Required output executable application |
|
103
|
0
|
|
|
|
|
|
my $exe = $param{exe}; |
|
104
|
0
|
0
|
0
|
|
|
|
unless ( $exe and $exe =~ /\.exe$/ ) { |
|
105
|
0
|
|
|
|
|
|
Carp::croak("Missing or invalid exe file"); |
|
106
|
|
|
|
|
|
|
} |
|
107
|
0
|
0
|
|
|
|
|
if ( -f $exe ) { |
|
108
|
0
|
|
|
|
|
|
Carp::croak("The target exe '$exe' already exists"); |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# Optional icon file |
|
112
|
0
|
|
0
|
|
|
|
my $ico = $param{ico} || ''; |
|
113
|
0
|
0
|
0
|
|
|
|
if ( $ico and not -f $ico ) { |
|
114
|
0
|
|
|
|
|
|
Carp::croak("Invalid ico file"); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# DOS or GUI application? |
|
118
|
0
|
|
|
|
|
|
my $dos = !! $param{dos}; |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# Hand off to the executable |
|
121
|
0
|
|
|
|
|
|
my $bat2exe = bat2exe_path(); |
|
122
|
0
|
|
|
|
|
|
my $stdin = ''; |
|
123
|
0
|
|
|
|
|
|
my $stdout = ''; |
|
124
|
0
|
|
|
|
|
|
my $stderr = ''; |
|
125
|
0
|
|
|
|
|
|
my $rv = IPC::Run3::run3( [ |
|
126
|
|
|
|
|
|
|
$bat2exe, $bat, $exe, $ico, $dos, |
|
127
|
|
|
|
|
|
|
], \$stdin, \$stdout, \$stderr ); |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
1; |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=pod |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 SUPPORT |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Bugs should be submitted via the CPAN bug tracker, located at |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
L |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
For general comments, contact the author. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 AUTHOR |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Adam Kennedy Eadamk@cpan.orgE |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
B Copyright 2009 Adam Kennedy. |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
This program is free software; you can redistribute |
|
155
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
The full text of the license can be found in the |
|
158
|
|
|
|
|
|
|
LICENSE file included with this module. |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
B Copyright 2006 - 2009 Fatih Kodak. |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
In order to use this program, you must read and agree with this |
|
163
|
|
|
|
|
|
|
license agreement. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
You may not translate, reverse program, disassemble, decompile or otherwise |
|
166
|
|
|
|
|
|
|
reverse engineer this program. |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
No warranty. The software is licensed to you "as is" and without any |
|
169
|
|
|
|
|
|
|
warranty. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
If you do not agree with this agreement, please do not use this software. |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
B Copyright 1999 - 2007 Tomasz Grysztar. All rights reserved. |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This program is free for commercial and non-commercial use as long as |
|
176
|
|
|
|
|
|
|
the following conditions are adhered to. |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Copyright remains Tomasz Grysztar, and as such any Copyright notices |
|
179
|
|
|
|
|
|
|
in the code are not to be removed. |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without |
|
182
|
|
|
|
|
|
|
modification, are permitted provided that the following conditions are |
|
183
|
|
|
|
|
|
|
met: |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, |
|
186
|
|
|
|
|
|
|
this list of conditions and the following disclaimer. |
|
187
|
|
|
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright |
|
188
|
|
|
|
|
|
|
notice, this list of conditions and the following disclaimer in the |
|
189
|
|
|
|
|
|
|
documentation and/or other materials provided with the distribution. |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
192
|
|
|
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
|
193
|
|
|
|
|
|
|
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
|
194
|
|
|
|
|
|
|
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR |
|
195
|
|
|
|
|
|
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
196
|
|
|
|
|
|
|
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
197
|
|
|
|
|
|
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
198
|
|
|
|
|
|
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
199
|
|
|
|
|
|
|
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
200
|
|
|
|
|
|
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
201
|
|
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
The licence and distribution terms for any publically available |
|
204
|
|
|
|
|
|
|
version or derivative of this code cannot be changed. i.e. this code |
|
205
|
|
|
|
|
|
|
cannot simply be copied and put under another distribution licence |
|
206
|
|
|
|
|
|
|
(including the GNU Public Licence). |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |