• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 395
  • Last Modified:

Expect.pm, sending long commands

I need to have my Perl script send up to 200 KB of text to an executing process's stdin, and only then await a response. I have been using Expect.pm, but it hangs when asked to send more than ~50KB of text. I've noticed that my shell (BASH on Cygwin on Windows XP) also won't let me append more than ~50KB of text to a program's stdin. Could this limitation be a function of Cygwin or Windows, rather than Expect.pm? How can I get around this?

Thank you.
0
bobwood2000
Asked:
bobwood2000
  • 4
  • 3
1 Solution
 
jmcgOwnerCommented:
Expect is using ptty (pseudo teletype) interfaces. There are traditionally limits in how much input can be entered on one line when using canonical text entry on a tty. I don't see how this particular limit could cause the hang you describe.

One thing to try is to have your Perl script break up what it is sending to the program into chunks considerably smaller than 50KB and pause between sending chunks. If a "sleep(1);" is too long, you can try using one of the other mechanisms (such as 'select') for a shorter interval.

Adding a pause is not going to help if there is really a deadlock between consumer and producer. If the process you are feeding the 200KB to is doing something else that can cause it to be blocked besides simply reading its input (for instance, if it is connected with a pipe back to your process or is reporting progress back to the ptty while reading), you may need to modify what you are doing to drain the stream that is getting clogged.

I'm not sure what you meant by the BASH on Cygwin on Windows example. How are you appending text? From a file? From the script itself with a << ("here document") redirection?
0
 
bobwood2000Author Commented:
Thanks for the feedback. I'll try breaking up the input into smaller chunks and let you know whether that works.

By "BASH on Cygwin on Windows" I meant that my operating system is Windows and BASH is my shell. I'm using Cygwin to provide a Unix-like environment while I'm running Windows, such that Expect.pm will work. Otherwise, Expect.pm doesn't support Windows.
0
 
jmcgOwnerCommented:
OK, I'll be interested to hear what you find out. I've not used Cygwin much, but it's hard to believe there'd be a limitation on the total amount you can pass to a program. The 50KB is approaching the 64KB that can be described by a 16-bit integer, so perhaps there's a limitation on individual buffers that can be attributed to a 16-bit legacy in the implementation.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
jmcgOwnerCommented:
Anything to report?

I've been pulled in other directions than paying attention to Experts Exchange this month. I'm still interested in finding out what the problem was and whether I can offer any more help.
0
 
bobwood2000Author Commented:
Yeah, breaking into chuncks didn't seem to do it. My "solution" has been just to not process data that is > 50 KB. This actually works well enough for my current project.
0
 
jmcgOwnerCommented:
Shall we close this question (I think it might be worth keeping in the database) and refund your points, since we didn't get you a resolution?
0
 
bobwood2000Author Commented:
Yes, sounds good. Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now