in reply to open2 or 3 run command using pty

Before trying to run an interactive session, consider trying to run the session in batch mode:

my $tempfile= '/tmp/sql_output'; my $sql = "select * from users"; open (COMMAND, "| /opt/sql >$tempfile" ) || die $!; print (COMMAND "connect credentials") print (COMMAND "$sql\n"); open my $results, '<', $tempfile or die "Couldn't read '$tempfile': $!"; while( <$results> ) { print $_; };

Trying to run a program interactively usually brings lots of problems when the program is buffering its output. So I prefer to stuff all commands into one string, send that string to the program, and then read the output from a file.

Replies are listed 'Best First'.
Re^2: open2 or 3 run command using pty
by klimenkoandrey (Initiate) on Jul 21, 2014 at 09:34 UTC
    with temp file same situation (i guess sql command insert stupid ">")

      Yes, most likely the sql command inserts the "prompt signs" on its own.

      Maybe you can find in the manual how you can change (or suppress) those signs. Sybase and Oracle use "variables" in their shell which you can use to change the prompt and the output format. Maybe your vendor uses something similar.

      Alternatively, you could mention the vendor of your database then maybe somebody knows either the appropriate DBD to use or how to make the command line shell output data in a way that you can reuse from within Perl.

        No i can't find documentation

        This is McAfee DB (NitroDB). I have no informations about it.

        I can remove this sign by perl, but if this sign will be legal in DB!?

Re^2: open2 or 3 run command using pty
by klimenkoandrey (Initiate) on Jul 21, 2014 at 10:03 UTC
    i maybe find something: when i use open2 and close Handler (WRITE) at the end of using (end of file) output stopped on last clear line. If close after sending last command, then I've got all output with ">" on next sting after stopped. Think this is buffer troubles. Is possible change size of output buffers manually?

      Not that I'm aware of. The size of the output buffers is determined by the child program, not by the parent.