我尝试从以下Perl脚本打印到标准输出,但它不会在屏幕上产生任何输出。但它会打印到文件中。
#!/usr/bin/perl
use warnings;
use strict;
print "Here's some text\n";
print STDERR "Here's some text\n";
print STDOUT "Here's some text\n";
open FH, ">", "file.txt" or die $!;
print FH "Here's some text\n";
我尝试使用(perl -v
)检查perl的版本,但是也没有输出任何东西。 perl手册页告诉我,我使用的是5.14.2。我从Raspberry Pi的bash提示符下运行Perl脚本。
我看到了类似的帖子Print: producing no output,所以我使用strace并看到输出中没有包含任何写命令。
strace perl -we'print("a") or die("Can'\''t print: $!\n");'
这是完整脚本的strace输出:
execve("./response", ["./response"], [/* 18 vars */]) = 0
brk(0) = 0xd98000
uname({sys="Linux", node="raspberrypi", ...}) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6f99000
access("/etc/ld.so.preload", R_OK) = 0
open("/etc/ld.so.preload", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=44, ...}) = 0
mmap2(NULL, 44, PROT_READ|PROT_WRITE, MAP_PRIVATE, 3, 0) = 0xb6f98000
close(3) = 0
open("/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\270\4\0\0004\0\0\0"..., 512) = 512
lseek(3, 7276, SEEK_SET) = 7276
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1080) = 1080
lseek(3, 7001, SEEK_SET) = 7001
read(3, "A.\0\0\0aeabi\0\1$\0\0\0\0056\0\6\6\10\1\t\1\n\2\22\4\24\1\25"..., 47) = 47
fstat64(3, {st_mode=S_IFREG|0755, st_size=10170, ...}) = 0
mmap2(NULL, 39740, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6f6c000
mprotect(0xb6f6e000, 28672, PROT_NONE) = 0
mmap2(0xb6f75000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1) = 0xb6f75000
close(3) = 0
munmap(0xb6f98000, 44) = 0
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=64456, ...}) = 0
mmap2(NULL, 64456, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb6f5c000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/usr/lib/libperl.so.5.14", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\220\v\2\0004\0\0\0"..., 512) = 512
lseek(3, 1346508, SEEK_SET) = 1346508
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1120) = 1120
lseek(3, 1346184, SEEK_SET) = 1346184
read(3, "A2\0\0\0aeabi\0\1(\0\0\0\0056\0\6\6\10\1\t\1\n\2\22\4\24\1\25"..., 51) = 51
fstat64(3, {st_mode=S_IFREG|0644, st_size=1347628, ...}) = 0
mmap2(NULL, 1379192, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6e0b000
mprotect(0xb6f4f000, 32768, PROT_NONE) = 0
mmap2(0xb6f57000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x144) = 0xb6f57000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libdl.so.2", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0(\t\0\0004\0\0\0"..., 512) = 512
lseek(3, 8652, SEEK_SET) = 8652
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1160) = 1160
lseek(3, 8320, SEEK_SET) = 8320
read(3, "A0\0\0\0aeabi\0\1&\0\0\0\0056\0\6\6\10\1\t\1\n\2\22\4\24\1\25"..., 49) = 49
fstat64(3, {st_mode=S_IFREG|0644, st_size=9812, ...}) = 0
mmap2(NULL, 41136, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6e00000
mprotect(0xb6e02000, 28672, PROT_NONE) = 0
mmap2(0xb6e09000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1) = 0xb6e09000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libm.so.6", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\3201\0\0004\0\0\0"..., 512) = 512
lseek(3, 426468, SEEK_SET) = 426468
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1160) = 1160
lseek(3, 426136, SEEK_SET) = 426136
read(3, "A0\0\0\0aeabi\0\1&\0\0\0\0056\0\6\6\10\1\t\1\n\2\22\4\24\1\25"..., 49) = 49
fstat64(3, {st_mode=S_IFREG|0644, st_size=427628, ...}) = 0
mmap2(NULL, 458912, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6d8f000
mprotect(0xb6df7000, 28672, PROT_NONE) = 0
mmap2(0xb6dfe000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x67) = 0xb6dfe000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libpthread.so.0", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\274V\0\0004\0\0\0"..., 512) = 512
lseek(3, 82712, SEEK_SET) = 82712
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1400) = 1400
lseek(3, 82308, SEEK_SET) = 82308
read(3, "A0\0\0\0aeabi\0\1&\0\0\0\0056\0\6\6\10\1\t\1\n\2\22\4\24\1\25"..., 49) = 49
fstat64(3, {st_mode=S_IFREG|0755, st_size=116462, ...}) = 0
mmap2(NULL, 123412, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6d70000
mprotect(0xb6d84000, 28672, PROT_NONE) = 0
mmap2(0xb6d8b000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x13) = 0xb6d8b000
mmap2(0xb6d8d000, 4628, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb6d8d000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libc.so.6", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\214y\1\0004\0\0\0"..., 512) = 512
lseek(3, 1215264, SEEK_SET) = 1215264
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1360) = 1360
lseek(3, 1214828, SEEK_SET) = 1214828
read(3, "A.\0\0\0aeabi\0\1$\0\0\0\0056\0\6\6\10\1\t\1\n\2\22\4\24\1\25"..., 47) = 47
fstat64(3, {st_mode=S_IFREG|0755, st_size=1216624, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6f98000
mmap2(NULL, 1258784, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6c3c000
mprotect(0xb6d62000, 32768, PROT_NONE) = 0
mmap2(0xb6d6a000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x126) = 0xb6d6a000
mmap2(0xb6d6d000, 9504, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb6d6d000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libcrypt.so.1", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\30\7\0\0004\0\0\0"..., 512) = 512
lseek(3, 29116, SEEK_SET) = 29116
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1160) = 1160
lseek(3, 28780, SEEK_SET) = 28780
read(3, "A0\0\0\0aeabi\0\1&\0\0\0\0056\0\6\6\10\1\t\1\n\2\22\4\24\1\25"..., 49) = 49
fstat64(3, {st_mode=S_IFREG|0644, st_size=30276, ...}) = 0
mmap2(NULL, 221504, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6c05000
mprotect(0xb6c0c000, 28672, PROT_NONE) = 0
mmap2(0xb6c13000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6) = 0xb6c13000
mmap2(0xb6c15000, 155968, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb6c15000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabihf/libgcc_s.so.1", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0`\364\0\0004\0\0\0"..., 512) = 512
lseek(3, 130212, SEEK_SET) = 130212
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1160) = 1160
lseek(3, 129880, SEEK_SET) = 129880
read(3, "A2\0\0\0aeabi\0\1(\0\0\0\0056\0\6\6\10\1\t\1\n\2\22\4\24\1\25"..., 51) = 51
fstat64(3, {st_mode=S_IFREG|0644, st_size=131372, ...}) = 0
mmap2(NULL, 162704, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6bdd000
mprotect(0xb6bfd000, 28672, PROT_NONE) = 0
mmap2(0xb6c04000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1f) = 0xb6c04000
close(3) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6f97000
set_tls(0xb6f976d0, 0xb6f97da8, 0xb6f9c048, 0xb6f976d0, 0xb6f9c048) = 0
mprotect(0xb6c13000, 4096, PROT_READ) = 0
mprotect(0xb6d6a000, 8192, PROT_READ) = 0
mprotect(0xb6d8b000, 4096, PROT_READ) = 0
mprotect(0xb6dfe000, 4096, PROT_READ) = 0
mprotect(0xb6e09000, 4096, PROT_READ) = 0
mprotect(0xb6f57000, 8192, PROT_READ) = 0
mprotect(0x11000, 4096, PROT_READ) = 0
mprotect(0xb6f9b000, 4096, PROT_READ) = 0
munmap(0xb6f5c000, 64456) = 0
set_tid_address(0xb6f97278) = 12607
set_robust_list(0xb6f97280, 0xc) = 0
futex(0xbece6778, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 1, NULL, b6d8c000) = -1 EAGAIN (Resource temporarily unavailable)
rt_sigaction(SIGRTMIN, {0xb6d7520c, [], SA_SIGINFO|0x4000000}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {0xb6d750b4, [], SA_RESTART|SA_SIGINFO|0x4000000}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM_INFINITY}) = 0
rt_sigaction(SIGFPE, {SIG_IGN, [FPE], SA_RESTART|0x4000000}, {SIG_DFL, [], 0}, 8) = 0
brk(0) = 0xd98000
brk(0xdb9000) = 0xdb9000
getuid32() = 1001
geteuid32() = 1001
getgid32() = 1004
getegid32() = 1004
open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=1534656, ...}) = 0
mmap2(NULL, 1534656, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb6a66000
close(3) = 0
open("/dev/urandom", O_RDONLY|O_LARGEFILE) = 3
read(3, "~\210\223\234", 4) = 4
close(3) = 0
gettimeofday({1460938704, 307768}, NULL) = 0
readlink("/proc/self/exe", "/usr/bin/perl", 4095) = 13
stat64("/usr/local/lib/site_perl/5.14.2/arm-linux-gnueabihf-thread-multi-64int", 0xbece6368) = -1 ENOENT (No such file or directory)
stat64("/usr/local/lib/site_perl/5.14.2", 0xbece6368) = -1 ENOENT (No such file or directory)
stat64("/usr/local/lib/site_perl/arm-linux-gnueabihf-thread-multi-64int", 0xbece6368) = -1 ENOENT (No such file or directory)
open("./response", O_RDONLY|O_LARGEFILE) = 3
ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbece627c) = -1 ENOTTY (Inappropriate ioctl for device)
_llseek(3, 0, [0], SEEK_CUR) = 0
fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
brk(0xddb000) = 0xddb000
read(3, "#!/usr/bin/perl\nuse warnings;\nus"..., 8192) = 210
stat64("/etc/perl/warnings.pmc", 0xbece5e10) = -1 ENOENT (No such file or directory)
stat64("/etc/perl/warnings.pm", 0xbece5d90) = -1 ENOENT (No such file or directory)
stat64("/usr/local/lib/perl/5.14.2/warnings.pmc", 0xbece5e10) = -1 ENOENT (No such file or directory)
stat64("/usr/local/lib/perl/5.14.2/warnings.pm", 0xbece5d90) = -1 ENOENT (No such file or directory)
stat64("/usr/local/share/perl/5.14.2/warnings.pmc", 0xbece5e10) = -1 ENOENT (No such file or directory)
stat64("/usr/local/share/perl/5.14.2/warnings.pm", 0xbece5d90) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/perl5/warnings.pmc", 0xbece5e10) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/perl5/warnings.pm", 0xbece5d90) = -1 ENOENT (No such file or directory)
stat64("/usr/share/perl5/warnings.pmc", 0xbece5e10) = -1 ENOENT (No such file or directory)
stat64("/usr/share/perl5/warnings.pm", 0xbece5d90) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/perl/5.14/warnings.pmc", 0xbece5e10) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/perl/5.14/warnings.pm", 0xbece5d90) = -1 ENOENT (No such file or directory)
stat64("/usr/share/perl/5.14/warnings.pmc", 0xbece5e10) = -1 ENOENT (No such file or directory)
stat64("/usr/share/perl/5.14/warnings.pm", {st_mode=S_IFREG|0644, st_size=15015, ...}) = 0
open("/usr/share/perl/5.14/warnings.pm", O_RDONLY|O_LARGEFILE) = 4
ioctl(4, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbece5be4) = -1 ENOTTY (Inappropriate ioctl for device)
_llseek(4, 0, [0], SEEK_CUR) = 0
read(4, "# -*- buffer-read-only: t -*-\n# "..., 8192) = 8192
read(4, "08\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x"..., 8192) = 6823
read(4, "", 8192) = 0
close(4) = 0
brk(0xdfc000) = 0xdfc000
stat64("/etc/perl/strict.pmc", 0xbece5e10) = -1 ENOENT (No such file or directory)
stat64("/etc/perl/strict.pm", 0xbece5d90) = -1 ENOENT (No such file or directory)
stat64("/usr/local/lib/perl/5.14.2/strict.pmc", 0xbece5e10) = -1 ENOENT (No such file or directory)
stat64("/usr/local/lib/perl/5.14.2/strict.pm", 0xbece5d90) = -1 ENOENT (No such file or directory)
stat64("/usr/local/share/perl/5.14.2/strict.pmc", 0xbece5e10) = -1 ENOENT (No such file or directory)
stat64("/usr/local/share/perl/5.14.2/strict.pm", 0xbece5d90) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/perl5/strict.pmc", 0xbece5e10) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/perl5/strict.pm", 0xbece5d90) = -1 ENOENT (No such file or directory)
stat64("/usr/share/perl5/strict.pmc", 0xbece5e10) = -1 ENOENT (No such file or directory)
stat64("/usr/share/perl5/strict.pm", 0xbece5d90) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/perl/5.14/strict.pmc", 0xbece5e10) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/perl/5.14/strict.pm", 0xbece5d90) = -1 ENOENT (No such file or directory)
stat64("/usr/share/perl/5.14/strict.pmc", 0xbece5e10) = -1 ENOENT (No such file or directory)
stat64("/usr/share/perl/5.14/strict.pm", {st_mode=S_IFREG|0644, st_size=879, ...}) = 0
open("/usr/share/perl/5.14/strict.pm", O_RDONLY|O_LARGEFILE) = 4
ioctl(4, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbece5be4) = -1 ENOTTY (Inappropriate ioctl for device)
_llseek(4, 0, [0], SEEK_CUR) = 0
read(4, "package strict;\n\n$strict::VERSIO"..., 8192) = 879
_llseek(4, 878, [878], SEEK_SET) = 0
_llseek(4, 0, [878], SEEK_CUR) = 0
close(4) = 0
read(3, "", 8192) = 0
open("file.txt", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 4
ioctl(4, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbece614c) = -1 ENOTTY (Inappropriate ioctl for device)
_llseek(4, 0, [0], SEEK_CUR) = 0
fstat64(4, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
fcntl64(4, F_SETFD, FD_CLOEXEC) = 0
rt_sigaction(SIG_0, NULL, {0xb6e18dc4, [TRAP RTMIN RT_1 RT_2 RT_3 RT_12 RT_13 RT_15 RT_16 RT_18 RT_19 RT_20 RT_25 RT_26 RT_27 RT_28 RT_29], SA_SIGINFO|0x85b8}, 8) = -1 EINVAL (Invalid argument)
rt_sigaction(SIGHUP, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGINT, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGQUIT, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGILL, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGTRAP, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGABRT, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGBUS, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGFPE, NULL, {SIG_IGN, [FPE], SA_RESTART|0x4000000}, 8) = 0
rt_sigaction(SIGKILL, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGUSR1, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGSEGV, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGUSR2, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGPIPE, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGALRM, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGTERM, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGSTKFLT, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGCONT, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGSTOP, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGTSTP, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGTTIN, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGTTOU, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGURG, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGXCPU, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGXFSZ, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGVTALRM, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGPROF, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGWINCH, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGIO, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGPWR, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGSYS, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_2, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_3, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_4, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_5, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_6, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_7, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_8, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_9, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_10, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_11, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_12, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_13, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_14, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_15, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_16, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_17, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_18, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_19, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_20, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_21, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_22, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_23, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_24, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_25, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_26, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_27, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_28, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_29, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_30, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_31, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGRT_32, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGABRT, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGIO, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGSYS, NULL, {SIG_DFL, [], 0}, 8) = 0
write(4, "Here's some text\n", 17) = 17
close(4) = 0
close(3) = 0
exit_group(0) = ?
关于它为什么不产生输出的任何想法? bash脚本可以将文本回显到标准格式。
当我在调试模式下运行脚本时,它会打印输出。
在命令行执行perl -v后退出代码来自$?是0.
执行
perl -e'print "foo" or die $!'
给出并退出代码9,但这似乎是由于死亡。 perl -v>文件没有写任何文件。
这是stat STDOUT的输出和用于将其写入文件的命令:
45826 | 261126 | 33188 | 1 | 1001 | 1004 | 0 | 0 | 1461024408 | 1461035504 | 1461035504 | 4096 | 0
perl -e 'open my $FH, ">file"; print $FH join "|", stat STDOUT '
答案 0 :(得分:6)
在开始阅读之前,先看一下这个命令的输出。一切都指向STDOUT指向不正确的地方。
ls -l /proc/$$/fd/{1,2}
在我的系统上我得到了这个,请注意它在我写这篇文章时确实发生了变化,因为这不是一次性编写的。
lrwx------ 1 root root 64 May 3 17:01 /proc/27806/fd/1 -> /dev/pts/1
lrwx------ 1 root root 64 May 3 17:01 /proc/27806/fd/2 -> /dev/pts/1
我怀疑上面的内容与你相似。对我来说,stat看起来很可疑,如果我有权访问filesytem,我会搜索它正在告诉我写入的文件。
sudo find / -printf "%i:\t%p\n"|grep 261126
如果当Perl开始将它的stdout等更改为错误的地方时,我会在脚本中添加一个很长的睡眠,然后进行搜索以查看它的位置。如果文件是常规文件并且它在文件系统上,则应该找到它。
我对STDOUT的统计
|dev |inode |mode |link |uid |gid |rdev |size |atime |mtime |ctime |blk |blka
|13 |3 |8592 |1 |1000|5 |34816|0 |1462301986|1462301986|1462301958|1024|0
您在STDOUT上的统计数据
|dev |inode |mode |link |uid |gid |rdev |size |atime |mtime |ctime |blk |blka
|45826 |261126 |33188 |1 |1001|1004|0 |0 |1461024408|1461035504|1461035504|4096|0
在我的dev
上有次要编号13,当我在设备下搜索它时看起来没问题。如果我们掩饰你的主要/次要你有... ...
major == 179
minor == 2
请注意,我原来是反过来的,直到Wumpus Q. Wumbley更正。
在我的机器上,这是
crw------- 1 root root 2, 179 Apr 29 12:50 ptya3
我的rdev
等于
major == 136
minor == 0
在我的Debian系统上,这是/dev/pts/0
。你的rdev
是0.我快速浏览了一下,有些人使用屏幕可能会遇到/dev/pts/N
的问题,即它不在那里,但这是我的猜测。
strace也很奇怪,我在系统上写了以下几行:
read(3, "#!/usr/bin/perl -w\n#use strict;\n"..., 8192) = 228
read(3, "", 8192) = 0
close(3) = 0
write(1, "Here's some text STDOUT\n", 24Here's some text STDOUT
) = 24
write(2, "Here's some text STDERR\n", 24Here's some text STDERR
) = 24
write(1, "Here's some text STDOUT\n", 24Here's some text STDOUT
) = 24
事实上,这些似乎没有出现在你的strace中确实非常奇怪。你可以通过弄乱$|
来改变出现的位置,但它们应该出现在某个地方。 Gilles注意到模式也很奇怪。如果你运行这个脚本......
#!/usr/bin/perl
use warnings;
use strict;
use Fcntl ':mode';
my $mode = 33188;
my $user_rwx = ($mode & S_IRWXU) >> 6;
print("user_rwx = $user_rwx\n");
my $group_read = ($mode & S_IRGRP) >> 3;
print("group_read = $group_read\n");
my $other_execute = $mode & S_IXOTH;
print("other_execute = $other_execute\n");
printf "Permissions are %04o\n", S_IMODE($mode), "\n";
my $is_setuid = $mode & S_ISUID;
print("is_setuid = $is_setuid\n");
my $is_directory = S_ISDIR($mode);
print("dir = $is_directory\n");
my $is_reg = S_ISREG($mode);
print("regular = $is_reg\n");
您可以看到STDOUT似乎指向常规文件。这将确认为什么rdev
为零,即如果stdout重定向到意味着是设备但实际上只是普通文件的东西。我已经看到类似奇怪的事情发生在设备未正确设置的chrooted环境中。
无论在退出时是否打开缓冲,缓冲区都应该被刷新,即你会看到对write sys调用的调用。在strace中根本没有写任何东西真的很奇怪。
答案 1 :(得分:4)
您提供的信息中有几条有趣的线索:
perl -e'print "foo" or die $!'
给出退出代码9,即EBADF,暗示STDOUT指向错误的文件描述符。这可能是一些任意数字(因为底层文件描述符只是数字),或者它可能是一个曾经打开但现在关闭的文件描述符。 (这也意味着它不会,例如,重定向到/ dev / null - 这将导致没有输出,但不会给出错误。)
您的strace
输出显示多个open
和close
来电,并且它们似乎都已配对 - 没有关闭STDOUT的证据。重要的是,在类似Unix的系统上,open
调用全部返回FD 3(以及后来,在FD 3仍在使用的情况下为FD 4) - open
通常返回最低的未使用FD ,这进一步证明了FD 1(通常的STDOUT)在你的过程开始后还没有关闭。
因此,其含义是STDOUT未连接到FD 1,但与其他FD相关联。运行以下内容应该告诉你它是什么FD:
perl -e 'open my $FH, ">", file.txt"; print $FH fileno(STDOUT)'
我猜这将是一些任意数字,并且是您在Raspberry Pi上安装特定问题的结果 - 可能是某些损坏的库。但是suggested作为Sebastian,您可以运行lsof
来查找您的流程已打开的FD(向您的脚本添加sleep
以保持其运行),或者查看在/ proc。但是STDOUT可能指的是实际上并不是开放FD的东西。有点好奇的是,strace
输出甚至没有显示对write
的错误调用;这意味着Perl确实知道FD是无效的。
另一个有趣的尝试是运行:
perl -e 'system qw(echo hello)'
如果它产生输出,那么这意味着子进程继承了一个仍然打开的FD 1,这进一步证明了Perl处于错误状态并且STDOUT与意外的FD相关联。
另一件要尝试的是:
perl -le 'open(STDOUT, ">&1"); print "hello"'
尝试修复" STDOUT通过从FD 1(我推断的仍然是开放的,并且与STDOUT无关)的FD dup2()
重新打开它。如果这产生了输出,那么至少它是一种可能的解决方法,但仍然不能解释原始原因(我担心这将是难以理解的)。
一方面注意:虽然perl -V
没有为您提供任何输出,但您可以通过运行获取信息:
perl -MConfig -le 'open my $FH, ">", version.txt"; print Config::myconfig(); print foreach Config::local_patches()'
第二部分,关于本地应用的补丁,可以提供关于您已经安装的perl
是否存在非标准内容的线索。
答案 2 :(得分:1)
尝试创建一个新的用户帐户并使用它来查看是否出现相同的问题,我也会在较新的Perl上尝试它,因为我无法在其上有5.22的pi上重现这个问题。这看起来非常像你的shell中有一些意想不到的东西,一个破坏的模块安装,或者你有一个神秘的提示命令吞噬输出。
在你的strace中缺少对STDOUT和STDERR的写入表明它们在代码部分运行之前以某种方式被错误地打开了。
答案 3 :(得分:-1)
尝试在$|=1
行之后添加use
:
#!/usr/bin/perl
use warnings;
use strict;
$|=1;
print "Here's some text\n";
print STDERR "Here's some text\n";
print STDOUT "Here's some text\n";
open FH, ">", "file.txt" or die $!;
print FH "Here's some text\n";
你的strace输出还显示打印到文件是在脚本退出时完成的,而不是在脚本运行时,因为Perl的输出缓冲。
如果$|=1
无效:请尝试获取脚本使用的FD:
#!/usr/bin/perl
system "ls -l /proc/$$/fd";
或
#!/usr/bin/perl
system "lsof -p $$";
他们应该给你一个提示输出的提示。