home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / ntcode / ntperlb / t / nt / spawn.nt < prev    next >
Encoding:
Text File  |  1995-05-19  |  1.1 KB  |  53 lines

  1. #
  2. # test for spawn function under NT
  3. #
  4.  
  5. print "1..2\n";
  6.  
  7.  
  8. pipe(myR, hisW) || die "Can't create my pipes: $!\n";
  9. pipe(hisR, myW) || die "Can't create his pipes: $!\n";
  10.  
  11. $cmd = "cmd /c dir/w";
  12.  
  13. &Spawn($cmd, $pid, hisR, fileno(hisW), hisW) ||
  14.     die ("error spawning command: $!\n"); # 
  15.  
  16. close hisW;
  17. close hisR;
  18.  
  19. $found_it = 0;
  20. while(<myR>) {
  21.     $found_it++ if /Volume Serial Number/;
  22. }
  23. close myR;
  24. close myW;
  25.  
  26. if ($found_it) {print "ok 1\n";} else {print "not ok 1\n";}
  27.  
  28. open (T, ">script.$$") || die "Can't open script.$$: $!\n";
  29. print T "\$line = <>;\n";
  30. print T "print \$line eq \"input test\\n\" ? \"ok\\n\" : \"not ok\\n\"\n";
  31. close T;
  32.  
  33. pipe(myR, hisW) || die "Can't create my pipes: $!\n";
  34. pipe(hisR, myW) || die "Can't create his pipes: $!\n";
  35.  
  36. &Spawn ("perl script.$$", $pid, hisR, hisW, hisW) ||
  37.     die ("error spawning write test: $!\n");
  38.  
  39. close hisR;
  40. close hisW;
  41. select(myW);
  42. $| = 1;
  43. print "input test\n";
  44. chop ($response = <myR>);
  45.  
  46. close myR;
  47. close myW;
  48.  
  49. select STDOUT;
  50.  
  51. print $response, " 2\n";
  52.  
  53. unlink("script.$$");