Home > Archive > PerlTk > February 2008 > Another variable question - getOpenFile
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Another variable question - getOpenFile
|
|
| PhillC 2008-01-10, 7:10 pm |
| In my program I have a file dialogue using getOpenFile. e.g.
my $select_input_file = $mw -> getOpenFile(-title=>"Select File");
Once the user has selected the file, I need to use this in a system
command. e.g.
system("cp ${select_input_file} /home/username/userselected-
moved.file")
Where ${select_input_file} is the variable containing the file
selected from the file dialogue.
At this time the system command does not work and returns:
cp: missing destination file operand after `/home/phillc/2573-9-
copied.mpg'
I'm guessing it's a problem with the $select_input_file variable. In
an earlier post to the group I was shown how to use -textvariable and
through further reading I found out about -variable. However, neither
of these seem to be valid for getOpenFile.
Can someone point me in the right direction to do what I am attempting
above?
Many thanks
Phill
| |
| Marc Dashevsky 2008-01-10, 7:10 pm |
| In article <3da3b971-d9fc-4e25-a829-541ee1f2f8e3@k39g2000hsf.googlegroups.com>,
phillclarke@gmail.com says...
> In my program I have a file dialogue using getOpenFile. e.g.
>
> my $select_input_file = $mw -> getOpenFile(-title=>"Select File");
>
> Once the user has selected the file, I need to use this in a system
> command. e.g.
>
> system("cp ${select_input_file} /home/username/userselected-moved.file")
>
> Where ${select_input_file} is the variable containing the file
> selected from the file dialogue.
>
> At this time the system command does not work and returns:
>
> cp: missing destination file operand after `/home/phillc/2573-9-copied.mpg'
So is the above filename the intended destination? If so, it probably
means that $select_input_file is undefined. Now, it should only be
undefined if the user canceled the dialog, so I don't know what to tell
you if a file was actually selected and the return value is still undef.
Also, instead of system("cp . . ."), consider:
use File::Copy;
copy($select_input_file, '/home/username/userselected-moved.file');
> I'm guessing it's a problem with the $select_input_file variable. In
> an earlier post to the group I was shown how to use -textvariable and
> through further reading I found out about -variable. However, neither
> of these seem to be valid for getOpenFile.
>
> Can someone point me in the right direction to do what I am attempting
> above?
--
Go to http://MarcDashevsky.com to send me e-mail.
| |
| smallpond 2008-01-11, 7:07 pm |
| On Jan 10, 5:28 pm, PhillC <phillcla...@gmail.com> wrote:
> In my program I have a file dialogue using getOpenFile. e.g.
>
> my $select_input_file = $mw -> getOpenFile(-title=>"Select File");
>
> Once the user has selected the file, I need to use this in a system
> command. e.g.
>
> system("cp ${select_input_file} /home/username/userselected-
> moved.file")
>
> Where ${select_input_file} is the variable containing the file
> selected from the file dialogue.
>
> At this time the system command does not work and returns:
>
> cp: missing destination file operand after `/home/phillc/2573-9-
> copied.mpg'
>
> I'm guessing it's a problem with the $select_input_file variable. In
> an earlier post to the group I was shown how to use -textvariable and
> through further reading I found out about -variable. However, neither
> of these seem to be valid for getOpenFile.
>
> Can someone point me in the right direction to do what I am attempting
> above?
>
> Many thanks
> Phill
my $select_input_file = $mw -> getOpenFile(-title=>"Select File");
print "Got: $select_input_file\n";
print "My current directory is: $ENV{PWD}\n";
print "Thinking of doing:
cp ${select_input_file} /home/username/userselected-moved.file\n";
| |
| PhillC 2008-01-12, 8:06 am |
| On 11 Jan, 16:08, smallpond <smallp...@juno.com> wrote:
> On Jan 10, 5:28 pm, PhillC <phillcla...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
> my $select_input_file = $mw -> getOpenFile(-title=>"Select File");
> print "Got: $select_input_file\n";
> print "My current directory is: $ENV{PWD}\n";
> print "Thinking of doing:
> cp ${select_input_file} /home/username/userselected-moved.file\n";
Thanks. I modified this a little to:
print "Got: $select_input_file\n";
print "My current directory is: $ENV{PWD}\n";
print "Thinking of doing:
cp ${select_input_file} /home/phillc/perl/newfile.pl\n";
And got this on the CLI:
Got: /home/phillc/perl/subroutine.pl
My current directory is: /home/phillc/perl
Thinking of doing:
cp /home/phillc/perl/subroutine.pl /home/phillc/perl/newfile.pl
However, after executing my system command I still got:
cp: missing destination file operand after `/home/phillc/perl/
newfile.pl'
So I tried something a little different:
print "Got: $select_input_file\n";
print "My current directory is: $ENV{PWD}\n";
print "Thinking of doing:
cp ${select_input_file} ${select_input_file}";
Which still resulted in:
Got: /home/phillc/perl/subroutine.pl
My current directory is: /home/phillc/perl
Thinking of doing:
cp /home/phillc/perl/subroutine.pl /home/phillc/perl/subroutine.pl
And then after system("cp ${select_input_file} ${select_input_file}");
-
cp: missing file operand
I was expecting a CLI dialogue about file already existing.
From my limited knowledge, it seems that the variable is being
assigned correctly.
The problem is most likely something very simple in Perl that I have
overlooked or forgotten how to do.
| |
| John W. Krahn 2008-01-12, 10:16 pm |
| PhillC wrote:
> On 11 Jan, 16:08, smallpond <smallp...@juno.com> wrote:
>
> Thanks. I modified this a little to:
>
> print "Got: $select_input_file\n";
> print "My current directory is: $ENV{PWD}\n";
> print "Thinking of doing:
> cp ${select_input_file} /home/phillc/perl/newfile.pl\n";
>
> And got this on the CLI:
>
> Got: /home/phillc/perl/subroutine.pl
> My current directory is: /home/phillc/perl
> Thinking of doing:
> cp /home/phillc/perl/subroutine.pl /home/phillc/perl/newfile.pl
>
> However, after executing my system command I still got:
>
> cp: missing destination file operand after `/home/phillc/perl/
> newfile.pl'
>
> So I tried something a little different:
>
> print "Got: $select_input_file\n";
> print "My current directory is: $ENV{PWD}\n";
> print "Thinking of doing:
> cp ${select_input_file} ${select_input_file}";
>
> Which still resulted in:
>
> Got: /home/phillc/perl/subroutine.pl
> My current directory is: /home/phillc/perl
> Thinking of doing:
> cp /home/phillc/perl/subroutine.pl /home/phillc/perl/subroutine.pl
>
> And then after system("cp ${select_input_file} ${select_input_file}");
> -
>
> cp: missing file operand
>
> I was expecting a CLI dialogue about file already existing.
>
> From my limited knowledge, it seems that the variable is being
> assigned correctly.
>
> The problem is most likely something very simple in Perl that I have
> overlooked or forgotten how to do.
$ENV{PWD} is probably going to be meaningless inside a perl program.
Use the Cwd module instead.
perldoc Cwd
You may also want to use the File::Copy module to copy files instead of
system('cp').
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
| |
| Willem 2008-02-24, 4:37 am |
| PhillC wrote:
) Thanks. I modified this a little to:
)
) print "Got: $select_input_file\n";
) print "My current directory is: $ENV{PWD}\n";
) print "Thinking of doing:
) cp ${select_input_file} /home/phillc/perl/newfile.pl\n";
)
) And got this on the CLI:
)
) Got: /home/phillc/perl/subroutine.pl
) My current directory is: /home/phillc/perl
) Thinking of doing:
) cp /home/phillc/perl/subroutine.pl /home/phillc/perl/newfile.pl
)
) However, after executing my system command I still got:
)
) cp: missing destination file operand after `/home/phillc/perl/
) newfile.pl'
You may want to try doing something like:
my $todo = "cp ${select_input_file} /output/file";
print "Thinking of doing: '$todo'\n";
system($todo);
To be absolutely sure that your debug print and your system are doing the
same thing and there is no silly typo or something in one of them.
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
|
|
|
|
|