$cmd = "echo 'exec javasplat.create_test_list(\'tests.txt\', \'$startStr\', \'$endStr\');' | $sqlplusconnect" ; system($cmd);
You haven't shown us the contents of those variables, so it's very hard to say what's going on. Please show a more representative code sample - see Short, Self-Contained, Correct Example.
In general: You're interpolating strings into the command to be executed, which is a potential security risk, also you have to be sure you're getting the quoting right. You're also using the shell to feed input into the command's STDIN. Both of these issues can be solved by using a module and avoiding the shell in the first place - I wrote about this topic at length here. Here's an example using IPC::Run3, which has the advantage of also being able to capture STDOUT and STDERR, if you like. Note that you still need to make sure that $startStr and $endStr are quoted properly, but you don't need to worry about escaping shell metacharacters anymore.
use warnings;
use strict;
use IPC::Run3;
my $stdin = q{exec javasplat.create_test_list('tests.txt',}
.qq{ '$startStr', '$endStr');};
run3 ['sqlplus','-s','username/password@host'], \$stdin
or die "run3 failed";
$? and die "external command failed, \$?=$?";
it is somehow truncating the trailing newlines from everyline, effectively writing the output to a single large line
How did you determine this? I would recommend looking at the file with a command like hexdump -C filename; maybe it's just a CR/LF problem.
I am doing the above thing in bash environment
Note that system calls the default shell at /bin/sh, which is not necessarily bash - see The problem of "the" default shell.
|