Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Another variable question - getOpenFile
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

Report this thread to moderator Post Follow-up to this message
Old Post
PhillC
01-11-08 12:10 AM


Re: Another variable question - getOpenFile
In article <3da3b971-d9fc-4e25-a829-541ee1f2f8e3@k39g2000hsf.googlegroups.co
m>,
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'[/color
]

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.

Report this thread to moderator Post Follow-up to this message
Old Post
Marc Dashevsky
01-11-08 12:10 AM


Re: Another variable question - getOpenFile
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";


Report this thread to moderator Post Follow-up to this message
Old Post
smallpond
01-12-08 12:07 AM


Re: Another variable question - getOpenFile
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.




Report this thread to moderator Post Follow-up to this message
Old Post
PhillC
01-12-08 01:06 PM


Re: Another variable question - getOpenFile
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

Report this thread to moderator Post Follow-up to this message
Old Post
John W. Krahn
01-13-08 03:16 AM


Re: Another variable question - getOpenFile
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

Report this thread to moderator Post Follow-up to this message
Old Post
Willem
02-24-08 09:37 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PerlTk archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 09:00 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.