Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Results 1 to 6 of 6

This is a discussion on Perl system() command not working in the Shared & Semi-Dedicated forum
When I try to get the Perl script I'm writing to do the following, the "Can't make new image" message comes up: system("cp $path_to_template_directory/$template_gif $path_to_output_directory/$new_image") ...

  1. #1
    Internet Marketing Fiend tigertom's Avatar
    Join Date
    May 2002
    Posts
    21

    Question Perl system() command not working

    When I try to get the Perl script I'm writing to do the following, the "Can't make new image" message comes up:

    system("cp $path_to_template_directory/$template_gif $path_to_output_directory/$new_image") or die "Can't make new image $new_image : $!";

    The paths and image names are correct.
    Nothing shows up in the error log.
    The output directory is chmoded to 707.

    Does JagPc allow scripts to run system commands?
    ---- TigerTom -----

    Download free Perl scripts to help YOU make that SALE.

  2. #2
    Loyal Client
    Join Date
    Sep 2001
    Location
    Wichita, KS
    Posts
    1,647
    try using bickticks instead --> `

  3. #3
    Internet Marketing Fiend tigertom's Avatar
    Join Date
    May 2002
    Posts
    21
    Quote Originally Posted by mattsiegman
    try using bickticks instead --> `
    I did:

    $cp_result = `cp "$path_to_template_directory/$template_gif $path_to_output_directory/$new_image"`;
    print $cp_result;

    This gave the error: 'missing destination file'

    $template_gif exists.
    $new_image is the one I'm tying to create.

    What could be the problem?

    Clues: The script does make one copy of the image, but fails to do so on subsequent passes (loops). It reports the error on all passes, even the first one.
    ---- TigerTom -----

    Download free Perl scripts to help YOU make that SALE.

  4. #4
    || $name ne 'R.Stiltskin'
    Join Date
    Jun 2003
    Location
    Tejas
    Posts
    2,438
    Quick and dirty, try:
    Code:
    #!/usr/bin/perl
    #
    #--------------------------------------------------
    # cpfile.pl [9/14/2004 7:06:33 AM]
    # Script to copy file
    #--------------------------------------------------
    
    use strict;
    use warnings;
    
    # Variables
    my $temppath = '/absolute/path/to/template/dir';
    my $tempfile = 'template.gif';
    my $output_d = '/absolute/path/to/template/dir/output';
    my $newimage = 'newpic.gif';
    
    # Output directory (chmod 755) MUST exist; if it
    # doesn't you may need a mkdir or an if exists loop
    
    system(`cp $temppath/$tempfile $output_d/$newimage`)
     or die "Cannot make new image $newimage : $!";
    
    print "$newimage created";
    
    exit;
    Don't know what parts you need but system calls work just fine. I think the syntax for cp is your main concern. This script fails under taint (you do use taint, right?) but there's not much point untainting this snippet unless you post all your code. Then the fees for assistance are no longer free.

  5. #5
    Internet Marketing Fiend tigertom's Avatar
    Join Date
    May 2002
    Posts
    21

    Smile

    God bless you sir! It WAS the syntax of cp what was the problem:

    It should have read:

    $cp_result = `cp $path_to_template_directory/$template_gif $path_to_output_directory/$new_image`;

    i.e. no quotation marks. Arrrgh!

    Thanks again
    ---- TigerTom -----

    Download free Perl scripts to help YOU make that SALE.

  6. #6
    || $name ne 'R.Stiltskin'
    Join Date
    Jun 2003
    Location
    Tejas
    Posts
    2,438
    You're welcome. Matt gets partial credit in spite of his verbosity.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •