Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!dali.cs.montana.edu!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!sun-barr!newstop!sun!amdcad!sono!porky!mayer From: mayer@sono.uucp (Ronald &) Newsgroups: comp.lang.perl Subject: `...` and open(F,'...|') VS system(...) with nonexistant programs Message-ID: Date: 24 May 91 22:21:03 GMT Sender: mayer@sono.uucp (Ronald Mayer) Organization: Acuson; Mountain View, California Lines: 10 When attempting to execute unix program from perl, I'm unable to both 1) Determine if the program was actually executed and 2) Get the output from the program into a perl string As shown below, the only ways I know of getting the output of a unix program into a perl string, `...` and open(F,'...|'), don't seem to be able to distinguish between a program with no output which returns false and a program which doesn't exist. This is in contrast to perl's 'system(...)', which returns a different value for nonexistant programs. #! /usr/local/bin/perl ### Unix programs: 'true' returns 0; 'false' returns 1; 'undef' doesnt exist. `true`, print "$?\n"; # 0 `false`, print "$?\n"; # 256 `undef`, print "$?\n"; # 256 (how do I distinguish this from `false`?) open(F,'true|') || die; ; close(F); print "$?\n"; # 0 open(F,'false|')|| die; ; close(F); print "$?\n"; # 256 open(F,'undef|')|| die; ; close(F); print "$?\n"; # 256, same question... print system('true'),"\n"; # 0 print system('false'),"\n"; # 256 print system('undef'),"\n"; # 65280 easily distinguishable from system('false') Does anyone know why? (I kinda assume that '``' and 'open' are using 'sh' or 'csh', which return the same value when executing 'false' as they do when they execute a nonexistant program. Is this correct?) Does anyone know of a workaround? (Other than parsing `which filename`?) Ron Mayer