Batch-Interpreter

 view release on metacpan or  search on metacpan

bin/runbat  view on Meta::CPAN

);

my %filename = (
	%{Batch::Interpreter->default_filenames},

	map {
		if (my ($unc, $sys) = /^([^=]++)=(.+)$/) {
			($unc => $sys)
		} else {
			die "missing system path in file name '$_'";
		}
	} @filename_opt
);

my @mountpoint = (
	map({
		if (my ($unc, $sys) = /^([^=]++)=(.+)$/) {
			($unc => $sys)
		} else {
			die "missing system path in mount point '$_'";
		}
	} @mountpoint_opt),

	$is_win_host ? (
	) : (
		'G:/' => '/mnt/g/',
		'A:/' => '/',
	),
);

my @remote_name = (
	'G:/' => '\\\\fileserver\\export',
);

my $interactive_mode;
my $lines;
if (@immediate_line) {
	$lines = \@immediate_line;
} elsif (!defined $prog) {
	$interactive_mode = 1;
	say STDERR "$PROGRAM $VERSION";
} elsif ($prog eq '-') {
	$lines = [ <STDIN> ];
} else {
	open my $fh, '<:crlf', $prog
		or die "$prog: $!";
	$lines = [ <$fh> ];
}

my $interpreter = Batch::Interpreter->new(
	dump_parse_tree => $dump_parse_tree,
	verbose_system => $verbose_system,
	verbose_set => $verbose_set,

	echo => !$interactive_mode,
	vars => \%var,
	varcases => \%varcase,
	terminal => -t STDIN ? Term::ReadLine->new('CON') : undef,

	version_string => 'Microsoft Windows [Version 6.1.7601]',
	locale => 'de_DE',

	filenames => \%filename,
	mountpoints => \@mountpoint,
	remote_names => \@remote_name,

	internal_commands => \%internal_command,
	external_commands => \%external_command,
);

# this is global state which is difficult to restore (even with PerlIO::Layers),
# so we can't do this in the interpreter
binmode STDOUT, ':crlf';
binmode STDERR, ':crlf';
binmode STDIN, ':crlf';

my $result = $interpreter->run({}, $lines, @ARGV);
if ($result =~ /^error/g) {
	say STDERR "ERROR".substr $result, pos $result;
	exit 99;
} else {
	exit $result;
}

__END__

=head1 NAME

runbat - usable real world example for Batch::Interpreter

=head1 SYNOPSIS

	runbat [--[no-]dump-parse-tree]
		[--[no-]verbose-system]	[--[no-]verbose-set]
		[--filename <name>=<path> ...]
		[--mount <mountpoint>=<path> ...]
		[--remote-name <mountpoint>=<remote name> ...]
		[-c <command> ...]
		[-- <batch file> [arguments] ...]

=head1 AUTHOR

Ralf Neubauer, C<< <ralf at strcmp.de> >>

=head1 BUGS

Please report any bugs or feature requests to C<bug-batch-interpreter at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Batch-Interpreter>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc runbat


You can also look for information at:

=over 4



( run in 0.808 second using v1.01-cache-2.11-cpan-ceb78f64989 )