Alien-BatToExeConverter

 view release on metacpan or  search on metacpan

lib/Alien/BatToExeConverter.pm  view on Meta::CPAN


  # Convert a batch script to an executable that will have an icon,
  # won't show a DOS box, and will suppress to the command line.
  Alien::BatToExeConverter::bat2exe(
      bat => 'C:\strawberry\perl\bin\foo.bat',
      exe => 'C:\strawberry\perl\bin\foo.exe',
      ico => 'C:\strawberry\perl\bin\foo.ico',
      dos => 0,
  );

The C<bat2exe> function is used to execute F<Bat_To_Exe_Converter.exe> and
generate an executable from the batch script. It takes a series of named
params, returning true on success or throwing an exception on failure.
The default settings are intended to produce an .exe script for launching
a GUI application.

The compulsory C<bat> param should be the name of the source batch script.

The compulsory C<exe> param should be the path to white the executable to,
and must NOT already exist.

The optional C<ico> param will bind an icon to the executable.

The optional C<dos> param will indicate that the executable is intended
for the command line. If C<not> supplied, STDOUT and STDERR will be
supressed and a "DOS box" will not be shown on execution.

=cut

sub bat2exe {
	my %param = @_;

	# Required input batch script
	my $bat = $param{bat};
	unless ( $bat and $bat =~ /\.bat$/ and -f $bat ) {
		Carp::croak("Missing or invalid bat file");
	}

	# Required output executable application
	my $exe = $param{exe};
	unless ( $exe and $exe =~ /\.exe$/ ) {
		Carp::croak("Missing or invalid exe file");
	}
	if ( -f $exe ) {
		Carp::croak("The target exe '$exe' already exists");
	}

	# Optional icon file
	my $ico = $param{ico} || '';
	if ( $ico and not -f $ico ) {
		Carp::croak("Invalid ico file");
	}

	# DOS or GUI application?
	my $dos = !! $param{dos};

	# Hand off to the executable
	my $bat2exe = bat2exe_path();
	my $stdin   = '';
	my $stdout  = '';
	my $stderr  = '';
	my $rv      = IPC::Run3::run3( [
		$bat2exe, $bat, $exe, $ico, $dos,
	], \$stdin, \$stdout, \$stderr );

	

	1;
}

1;

=pod

=head1 SUPPORT

Bugs should be submitted via the CPAN bug tracker, located at

L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Alien-BatToExeConverter>

For general comments, contact the author.

=head1 AUTHOR

Adam Kennedy E<lt>adamk@cpan.orgE<gt>

=head1 COPYRIGHT

B<Alien::BatToExeConverter> Copyright 2009 Adam Kennedy.

This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the
LICENSE file included with this module.

B<Bat_To_Exe_Converter.exe> Copyright 2006 - 2009 Fatih Kodak.

In order to use this program, you must read and agree with this
license agreement.

You may not translate, reverse program, disassemble, decompile or otherwise
reverse engineer this program.

No warranty. The software is licensed to you "as is" and without any
warranty.

If you do not agree with this agreement, please do not use this software.

B<Flat Assembler> Copyright 1999 - 2007 Tomasz Grysztar. All rights reserved.

This program is free for commercial and non-commercial use as long as
the following conditions are adhered to.

Copyright remains Tomasz Grysztar, and as such any Copyright notices
in the code are not to be removed.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

1. Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright



( run in 0.538 second using v1.01-cache-2.11-cpan-9581c071862 )