9 # supress VMS whinging about bad execs.
10 use vmsish qw(hushed);
12 $| = 1; # flush stdout
14 $ENV{LC_ALL} = 'C'; # Forge English error messages.
15 $ENV{LANGUAGE} = 'C'; # Ditto in GNU.
17 my $Is_VMS = $^O eq 'VMS';
18 my $Is_Win32 = $^O eq 'MSWin32';
22 my $Perl = which_perl();
26 skip("bug/feature of pdksh", 2) if $^O eq 'os2';
28 my $tnum = curr_test();
29 $exit = system qq{$Perl -le "print q{ok $tnum - interp system(EXPR)"}};
31 is( $exit, 0, ' exited 0' );
34 my $tnum = curr_test();
35 $exit = system qq{$Perl -le "print q{ok $tnum - split & direct system(EXPR)"}};
37 is( $exit, 0, ' exited 0' );
39 # On VMS and Win32 you need the quotes around the program or it won't work.
40 # On Unix its the opposite.
41 my $quote = $Is_VMS || $Is_Win32 ? '"' : '';
43 $exit = system $Perl, '-le',
44 "${quote}print q{ok $tnum - system(PROG, LIST)}${quote}";
46 is( $exit, 0, ' exited 0' );
49 # Some basic piped commands. Some OS's have trouble with "helpfully"
50 # putting newlines on the end of piped output. So we split this into
51 # newline insensitive and newline sensitive tests.
52 my $echo_out = `$Perl -e "print 'ok'" | $Perl -le "print <STDIN>"`;
53 $echo_out =~ s/\n\n/\n/g;
54 is( $echo_out, "ok\n", 'piped echo emulation');
57 # here we check if extra newlines are going to be slapped on
59 local $TODO = 'VMS sticks newlines on everything' if $Is_VMS;
61 is( scalar `$Perl -e "print 'ok'"`,
62 "ok", 'no extra newlines on ``' );
64 is( scalar `$Perl -e "print 'ok'" | $Perl -e "print <STDIN>"`,
65 "ok", 'no extra newlines on pipes');
67 is( scalar `$Perl -le "print 'ok'" | $Perl -le "print <STDIN>"`,
68 "ok\n\n", 'doubled up newlines');
70 is( scalar `$Perl -e "print 'ok'" | $Perl -le "print <STDIN>"`,
71 "ok\n", 'extra newlines on inside pipes');
73 is( scalar `$Perl -le "print 'ok'" | $Perl -e "print <STDIN>"`,
74 "ok\n", 'extra newlines on outgoing pipes');
78 is( system(qq{$Perl -e "exit 0"}), 0, 'Explicit exit of 0' );
80 my $exit_one = $Is_VMS ? 4 << 8 : 1 << 8;
81 is( system(qq{$Perl "-I../lib" -e "use vmsish qw(hushed); exit 1"}), $exit_one,
82 'Explicit exit of 1' );
85 $rc = system "lskdfj";
86 unless( ok($rc == 255 << 8 or $rc == -1 or $rc == 256) ) {
87 print "# \$rc == $rc\n";
90 unless ( ok( $! == 2 or $! =~ /\bno\b.*\bfile/i or
91 $! == 13 or $! =~ /permission denied/i or
92 $! == 22 or $! =~ /invalid argument/ ) ) {
93 printf "# \$! eq %d, '%s'\n", $!, $!;
97 is( `$Perl -le "print 'ok'"`, "ok\n", 'basic ``' );
98 is( <<`END`, "ok\n", '<<`HEREDOC`' );
99 $Perl -le "print 'ok'"
104 my $tnum = curr_test();
105 if( $^O =~ /Win32/ ) {
106 print "not ok $tnum - exec failure doesn't terminate process " .
107 "# TODO Win32 exec failure waits for user input\n";
112 ok( !exec("lskdjfalksdjfdjfkls"),
113 "exec failure doesn't terminate process");
116 my $test = curr_test();
117 exec $Perl, '-le', qq{${quote}print 'ok $test - exec PROG, LIST'${quote}};
118 fail("This should never be reached if the exec() worked");