0

i am trying to execute following unix command but its not getting executed

$array_of_tables= `dbsmp $srv_name`;
print "$array_of_tables\n";

please help me to find out list of tables in a data base through perl scripting.

Also i am trying to copy a file from a path to different path by using following command:-

copy(`cd /osp/slee/service/$srv_name/bin/exec/script.txt`,`cd /osp/local/home/linus/amit/scripts`);

but getting an error:-

Usage: copy(FROM, TO [, BUFFERSIZE])

please provide some solution Thanks

2
  • Your second command should simply be copy('/osp/.../script.txt', '/osp/.../scripts'); (note the apostrophes are not backticks) Commented Jan 8, 2015 at 6:52
  • Just don't invoke external commands and use robust and portable core modules, perldoc.perl.org/File/Copy.html Commented Jan 8, 2015 at 6:55

2 Answers 2

3

Use doublequotes instead of back ticks.

copy("/osp/slee/service/$srv_name/bin/exec/script.txt","/osp/local/home/linus/amit/scripts");

and remove the cd

Sign up to request clarification or add additional context in comments.

1 Comment

Now i am not getting that particular error but file is not getting copied at the given path. Is there any other method to copy a file at unix platform in perl scripting ?
0

In Perl, the preferable way to capture the output of a system (shell) command is the qx() operator. See http://perldoc.perl.org/perlop.html#Quote-Like-Operators.

$array_of_tables = qx(dbsmp $srv_name);
print("$array_of_tables\n");

Actually, backticks should also work, so the problem must lie with your dbsmp command. I'm not sure what that command is; you'll have to provide more information about the utility and what error you're seeing.

For comparison, I can retrieve the list of tables in my local postgres database as a pipe-separated table using this shell command:

> psql -tAXq main postgres <<<\\d;

And this can be run from Perl as follows:

> perl -e 'print(qx(psql -tAXq main postgres <<<\\\\d;));'

1 Comment

backticks are the qx operator (just like double quotes are qq and single quotes are q)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.