Command "dir" not found in C:/MinGW/bin, C:/Python27,..... when use IPC::Run

Command "dir" not found in C:/MinGW/bin, C:/Python27,..... when use IPC::Run

am 21.07.2011 12:50:36 von hsin

I came across this error when I run follow code on windows.
and if changed the command `dir` to `ipconfig`, it's ok.
I guess it because dir is a cmd internal command but ipconfig isn't.

Can anybody explain it for me.

Thanks

code:

use strict;
use IPC::Run qw(run timeout);

my @cmd = qw(dir);
my ($in, $out, $error);
open $in, " open $out, ">out.txt";
open $error, ">error.txt";

run \@cmd, $in, $out, $error, timeout(10) or die "error: $?";

close $in;
close $out;
close $error;


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Command "dir" not found in C:/MinGW/bin, C:/Python27,..... whenuse IPC::Run

am 21.07.2011 15:10:43 von Shlomi Fish

Hi hsin,

On Thu, 21 Jul 2011 03:50:36 -0700 (PDT)
hsin wrote:

> I came across this error when I run follow code on windows.
> and if changed the command `dir` to `ipconfig`, it's ok.
> I guess it because dir is a cmd internal command but ipconfig isn't.

I think that's the case. You shouldn't depend on "dir" from within Perl
anyway because Perl has native and portable routines and modules to query the
file system:

http://perl-begin.org/uses/sys-admin/

Regards,

Shlomi Fish

>
> Can anybody explain it for me.
>
> Thanks
>
> code:
>
> use strict;
> use IPC::Run qw(run timeout);
>
> my @cmd = qw(dir);
> my ($in, $out, $error);
> open $in, " > open $out, ">out.txt";
> open $error, ">error.txt";
>
> run \@cmd, $in, $out, $error, timeout(10) or die "error: $?";
>
> close $in;
> close $out;
> close $error;
>
>



--
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
Understand what Open Source is - http://shlom.in/oss-fs

Chuck Norris is a real programmer. He writes programs by implementing the most
optimised machines for them using real atoms.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/