Problem: psql -c works but psql -f fails when executed from a Perl script using system().

From: "Jan Bessels" <jbessels(at)planet(dot)nl>
To: pgsql-general(at)postgresql(dot)org
Subject: Problem: psql -c works but psql -f fails when executed from a Perl script using system().
Date: 2002-10-24 13:16:30
Message-ID: ap8rvt$ib7$1@reader12.wxs.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I want to execute a sql statement from Perl using system() and psql.
Using -c it works like a charm. For some reason it fails to execute them
when I use the -f option (and <) . Excuting the command given to system()
from a Unix prompt (sh and/or bash) works however like a charm. According to
perldoc -f system the command does the following "the entire argument is
passed to the system's command shell for parsing (this is "/bin/sh -c" on
Unix platforms.". When I manually execute the command using sh -c'command"
it also works correctly.

What works is:
----------------
/usr/local/pgsql/bin/psql -e -d dwhtest -U username -h server <
/tmp/filldatabasetest.sql
sh -c "/usr/local/pgsql/bin/psql -e -d dwhtest -U username -h server <
/tmp/filldatabasetest.sql"
a prog.sh file which contains the line "usr/local/pgsql/bin/psql -e -d
dwhtest -U username -h server < /tmp/filldatabasetest.sql"

What fails is, piece of the perlcode:
-------------
my $cmd="
/usr/local/pgsql/bin/psql -e -d dwhtest -U username -h server <
/tmp/filldatabasetest.sql";
system("$cmd");

contents file /tmp/filldatabasetest.sql
-------------------------------------
INSERT INTO fieldsize_test values ( 2,'some text ');

Any other statement like "delete from fieldsize_test;" also fails.

I hope anyone can explain me why it fails and/or what I'm doing wrong.
Personally I'm baffled.

Remark1: I did found out that there are issues with -f and that < is better
for large files with sql statements. Mine can be a few MB's in size.
Remark2: I can't -c because of shell buffer size limits.

Jan

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2002-10-24 13:42:46 Re: Simulating a SELECT..FOR UPDATE to LOCK and SELECT statement
Previous Message Armin Faltl 2002-10-24 12:59:33 Why not --with-java?