Advertisement

03.27.2008 at 06:38AM PDT, ID: 23273934
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

IPC::Open2 not returning data on READER

Tags: Perl, 5.8.0, OSF, Perl, 5.8.0
I am using IPC::Open2 to create a shell that I can communicate with in Perl on a *nix machine.  I create the shell using the following code:

open2(\*READER, \*WRITER, "ksh");

and it creates the shell and returns the PID #.

Then, when I want to execute a command in the shell, I use the following code:

      my @results = ();
      print WRITER "$cmd\n";
      print WRITER "echo Done\n";
      while(<READER>)
      {
            if/Done/{last;}
            push(@results, $_);
        }

For the sake of this example, lets say that $cmd = "ls".  This code works very well on most of my machines.  I have 1 machines that is running OSF1 that I do not get any data back from the READER.  I can change the command to $cmd = "ls > /tmp/t.txt" and the t.txt file is created with the data, so I know that the commands are executing in the shell.  

Does anyone know what would prevent data from being returned on the READER handle?

Thanks...


Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: nbtzlp3
Solution Provided By: ahoffmann
Participating Experts: 1
Solution Grade: A
Views: 4
Translate:
Loading Advertisement...
03.28.2008 at 12:10AM PDT, ID: 21228462

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.28.2008 at 05:26AM PDT, ID: 21229697

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.30.2008 at 12:52PM PDT, ID: 21241719

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.31.2008 at 08:51AM PDT, ID: 21246471

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.31.2008 at 12:34PM PDT, ID: 21248370

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.31.2008 at 12:39PM PDT, ID: 21248413

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.31.2008 at 11:51PM PDT, ID: 21251716

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.01.2008 at 10:11AM PDT, ID: 21256002

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.01.2008 at 01:34PM PDT, ID: 21257845

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.01.2008 at 02:41PM PDT, ID: 21258383

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.01.2008 at 11:30PM PDT, ID: 21260562

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.02.2008 at 05:00AM PDT, ID: 21262062

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.02.2008 at 05:14AM PDT, ID: 21262161

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.02.2008 at 09:51AM PDT, ID: 21264962

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.02.2008 at 10:00AM PDT, ID: 21265032

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.02.2008 at 11:27PM PDT, ID: 21270083

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
03.28.2008 at 12:10AM PDT, ID: 21228462

Rank: Guru

depends on the implementation of the shell and on the used echo command (shell built.in or something like /usr/bin/echo) which most likely write to tty instead of STDOUT
 
03.28.2008 at 05:26AM PDT, ID: 21229697
I'm not sure I understand "implementation of the shell".  I am using the ksh shell.  Is there something I need to check about the shell to determine if it will work properly?

When you are commenting on the echo command.  Is that due to my using "echo Done\n", so that I can determine when the output is complete?

If so, the issue is that the original command doesn't produce any output on the READER handle at all.  The while<READER> loop is never entered.

If I have misunderstood, please let me know.

Thanks...
 
03.30.2008 at 12:52PM PDT, ID: 21241719

Rank: Guru

> .. using the ksh shell
ksh is one of those shells with infinite variations of implementation, So please tell us if you use the buil-in echo or one of the binary echo programs

> commenting on the echo
sometimes you can identify it with:
  which echo
(but that's unreliable in some cases), just try what happens if you do in a shell:

  echo -e 'e\te'
  /bin/echo -e 'e\te'
  /usr/bin/echo -e 'e\te'

> .. original command
what is the "original command"?
 
03.31.2008 at 08:51AM PDT, ID: 21246471
I believe that I am using the built in echo.  When I run the echo commands that you listed, I get the same output for all:  -e e     e

The original command that I am referencing is "ls".    If you look at the code that I am executing:

      my @results = ();
      print WRITER "$cmd\n";
      print WRITER "echo Done\n";
      while(<READER>)
      {
            if/Done/{last;}
            push(@results, $_);
      }

I stated that for the sake of this exercise, I am using "ls" as $cmd.  I'm not sure what the echo command has to do with the issue.  Shouldn't the ls command return data on the <READER> handle?

Thanks....

 
03.31.2008 at 12:34PM PDT, ID: 21248370

Rank: Guru

> I'm not sure what the echo command has to do with the issue.
The example you posted in the question uses echo.
Does it work if you replace echo by ksh's print or by /usr/bin/echo?
 
03.31.2008 at 12:39PM PDT, ID: 21248413
Echo is only used so that when I am reading the data from the <READER> handle, I know when to exit the loop.  I should FIRST received the data output by the ls command and then after I loop through all of that, then I should see the word DONE (as output by the echo command).  I an NOT receiving ANY data on the <READER> handle, therefore, I'm not even getting to the echo output.

I will try the print statement instead and see if it gives me any different results.

Thanks....
 
03.31.2008 at 11:51PM PDT, ID: 21251716

Rank: Guru

> Echo is only used so that when I am reading the data from the ..
hope you're aware that this breaks your reader if you have a file or whatever named "Done".
Anyway, please replace
  open2(\*READER, \*WRITER, "ksh");
by
  open2(\*READER, \*WRITER, "/bin/ksh")  || die "ERROR: $!"
or
  my $pid = open2(\*READER, \*WRITER, "/bin/ksh"); print "PID: $pid\n";

 If this doesnt help or give more hints, then please replace ksh by sh (I mean Bourne shell, not bash!).
Also open2 and open3 are known to have problems with STDIN and buffering, see man IPC::Open3 (which also relates to my very first comment).
 
04.01.2008 at 10:11AM PDT, ID: 21256002
Yes, I understand about the string "Done" breaking the reader.  The commands that I am actually using won't generate that string.

I have tried /bin/ksh and /bin/sh with no change in behavior.  
 
04.01.2008 at 01:34PM PDT, ID: 21257845

Rank: Guru

hmm, running out of ideas ...
set your $cmd to produse a huge output (> 8kb)
 
04.01.2008 at 02:41PM PDT, ID: 21258383
We might be getting somewhere.  I used a "cat /fullpathto/largetxtfile.txt" as the command.  The file exists and is > 8kb.  I got the following error when I printed the command to <WRITER>:

cat: Cannot stat stdout

Does this mean anything to you?
 
04.01.2008 at 11:30PM PDT, ID: 21260562

Rank: Guru

> cat: Cannot stat stdout
well, that seems to prove what I said in my very first comment: sounds like your shell (ksh) is writing to the tty, not STDOUT
Another reason may be a corrupted IPC module. Try to use IPC::open3 or code that yourself using fork(), dup() and open() (examples are in perl's man page).
 
04.02.2008 at 05:00AM PDT, ID: 21262062
I had previously tried open3 instead of open 2 with no results.  So, if the shell is writing to the tty instead of STDOUT, what can I do to redirect the output?  Would it be something like print "$cmd >&2"?

Thanks...
 
04.02.2008 at 05:14AM PDT, ID: 21262161
Whoops, maybe that should be "$cmd >&1" instead.
 
04.02.2008 at 09:51AM PDT, ID: 21264962

Rank: Guru

> .. writing to the tty instead of STDOUT, what can I do to redirect the output?
i.g. you cannot.
The only possibilty I know is to run your shell in a screen session.
 
04.02.2008 at 10:00AM PDT, ID: 21265032
Then I have a silly question.  This code works on many other machines.  Why doesn't this shell write it to STDOUT like the others do and will the other shells on this machine have the same issue?


 
04.02.2008 at 11:27PM PDT, ID: 21270083

Rank: Guru

> .. works on many other machines.
that's a vague description.
Are these machines the same UNIX kernel, the same shell, the same perl, the same perl modules? (means that shell, perl and modules are compiled for the system but are the same version)
Accepted Solution
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628