Platypus - Current Working Directory - write files

Platypus - Current Working Directory - write files

am 06.11.2007 01:06:22 von youcontrol

Hi,

Trying to use Platypus to create an app out of a Perl script. Bu I
can't get the 'Getting Current Working Directory' (ie, cd "$1/.." ) to
work in a Perl script. My minimal Perl script would look this:

#! /usr/bin/perl

# Create content
$content = "This is a test.";

# Save file
$name = "filename.txt";
$namestr = ">" . $name;
open NEWFILE, $namestr;
truncate NEWFILE, 1;
print NEWFILE "$content";
close NEWFILE;

I've tried wrapping the cd into a system call but did not get very far.
If you have anything you can point me at, I'd be very glad.

Wrapping this with Platypus does not produce any error messages but it
does not create the file (or I can't find it).

Thanks.

Markus

Re: Platypus - Current Working Directory - write files

am 06.11.2007 02:30:52 von kenslaterpa

On Nov 5, 7:06 pm, Markus S wrote:
> Hi,
>
> Trying to use Platypus to create an app out of a Perl script. Bu I
> can't get the 'Getting Current Working Directory' (ie, cd "$1/.." ) to
> work in a Perl script. My minimal Perl script would look this:
>
> #! /usr/bin/perl

Always include:
use strict;
use warnings;

These will help you in the long run even though you will be forced to
define all variables used.

>
> # Create content
> $content = "This is a test.";
>
> # Save file
> $name = "filename.txt";
> $namestr = ">" . $name;
> open NEWFILE, $namestr;

use the three argument form of open, use lexical filehandles and
handle the error condition.

open my $NEWFILE, '>', $name or die
"Unable to open $name for output: $!";

> truncate NEWFILE, 1;
> print NEWFILE "$content";
> close NEWFILE;
>
> I've tried wrapping the cd into a system call but did not get very far.
> If you have anything you can point me at, I'd be very glad.
>
> Wrapping this with Platypus does not produce any error messages but it
> does not create the file (or I can't find it).
>

I know nothing about Platypus, and you have no 'cd' in your code, so
I'm not certain I understand waht you are saying.

If you are saying you tried the system call in the Perl script, that
will not work as the system call creates a new process and the 'cd'
command will be executed in the new process. If you want to change a
directory in Perl use the 'chdir' function ('perldoc chdir' for
documentation).

> Thanks.
>
> Markus

HTH, Ken

Re: Platypus - Current Working Directory - write files

am 06.11.2007 03:13:52 von Tad McClellan

Markus S wrote:

> Trying to use Platypus


What is Platypus?


> to create an app out of a Perl script. Bu I
> can't get the 'Getting Current Working Directory' (ie, cd "$1/.." ) to
> work in a Perl script.


There is no attempt to change directories in your code.

What did you try already?


> print NEWFILE "$content";


perldoc -q vars

What’s wrong with always quoting "$vars"?

so,

print NEWFILE $content;


> I've tried wrapping the cd into a system call but did not get very far.
> If you have anything you can point me at, I'd be very glad.


perldoc -f chdir

perldoc -q change

I {changed directory, modified my environment} in a perl script. How
come the change disappeared when I exited the script? How do I get my
changes to be visible?


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"

Re: Platypus - Current Working Directory - write files

am 06.11.2007 05:02:53 von Larry

In article <472fafff@news1-rz-ap.ethz.ch>,
Markus S wrote:

> Trying to use Platypus to create an app out of a Perl script. Bu I
> can't get the 'Getting Current Working Directory' (ie, cd "$1/.." ) to
> work in a Perl script. My minimal Perl script would look this:

in Platypus window:

Script Type: Shell
Script Path: your start.sh

the followin is the start.sh file:

#!/bin/sh
#
# start.sh

cd $1/Contents/Resources/

/usr/bin/perl $1/Contents/Resources/my_perl_script.pl

Re: Platypus - Current Working Directory - write files

am 06.11.2007 07:40:52 von Ben Morrow

Quoth Larry :
> In article <472fafff@news1-rz-ap.ethz.ch>,
> Markus S wrote:
>
> > Trying to use Platypus to create an app out of a Perl script. Bu I
> > can't get the 'Getting Current Working Directory' (ie, cd "$1/.." ) to
> > work in a Perl script. My minimal Perl script would look this:
>
> in Platypus window:
>
> Script Type: Shell
> Script Path: your start.sh
>
> the followin is the start.sh file:
>
> #!/bin/sh
> #
> # start.sh
>
> cd $1/Contents/Resources/
>
> /usr/bin/perl $1/Contents/Resources/my_perl_script.pl

If that works (I've no idea what Platypus is, so I can't comment on
that) then you can do it in Perl instead:

Script Type: Shell
Script Path: this perl script:

#!/usr/bin/perl

use strict;
use warnings;

# it's always worth being portable when it's easy...
use File::Spec::Functions;

my $Res = catdir $ARGV[0], qw/Contents Resources/;
chdir $Res or die "can't cd to '$Res': $!";

# carry on...

Ben

Re: Platypus - Current Working Directory - write files

am 06.11.2007 12:38:38 von Joe Smith

Tad McClellan wrote:

> What ⠀ ™ s wrong with always quoting "$vars"?

Tad,
The headers on your posting says

Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
User-Agent: slrn/0.9.8.1pl1 (Linux)

yet the article body has UTF-8 characters.

-Joe

Re: Platypus - Current Working Directory - write files

am 06.11.2007 13:25:52 von youcontrol

On 2007-11-06 5:02, Larry said:

> in Platypus window:
>
> Script Type: Shell
> Script Path: your start.sh
>
> the followin is the start.sh file:
>
> #!/bin/sh
> #
> # start.sh
>
> cd $1/Contents/Resources/
>
> /usr/bin/perl $1/Contents/Resources/my_perl_script.pl

Thanks. Unfortunately, the $1 contains a space in my case and the cd
command therefore fails. I would know how to deal with this within Perl
but not on the Shell level.

(For all others, you can find out about Platypus here:
http://www.sveinbjorn.org/platypus)

Re: Platypus - Current Working Directory - write files

am 07.11.2007 01:34:43 von rvtol+news

Joe Smith schreef:
> Tad McClellan wrote:
>
>> What ⠀ ™ s wrong with always quoting "$vars"?
>
> Tad,
> The headers on your posting says
>
> Mime-Version: 1.0
> Content-Type: text/plain; charset=iso-8859-1
> Content-Transfer-Encoding: 8bit
> User-Agent: slrn/0.9.8.1pl1 (Linux)
>
> yet the article body has UTF-8 characters.

Yes, Tad does that frequently. He could just use

LANG= perldoc -q vars

before copy/pasting, but he insists in forgetting that.

--
Affijn, Ruud

"Gewoon is een tijger."

Re: Platypus - Current Working Directory - write files

am 07.11.2007 03:12:15 von Tad McClellan

Dr.Ruud wrote:
> Joe Smith schreef:
>> Tad McClellan wrote:
>>
>>> What ⠀ ™ s wrong with always quoting "$vars"?
>>
>> Tad,
>> The headers on your posting says
>>
>> Mime-Version: 1.0
>> Content-Type: text/plain; charset=iso-8859-1
>> Content-Transfer-Encoding: 8bit
>> User-Agent: slrn/0.9.8.1pl1 (Linux)
>>
>> yet the article body has UTF-8 characters.
>
> Yes, Tad does that frequently. He could just use
>
> LANG= perldoc -q vars
>
> before copy/pasting, but he insists in forgetting that.


Rather, I keep forgetting to

perldoc -uq vars

before copy/paste.


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"

Re: Platypus - Current Working Directory - write files

am 10.11.2007 23:24:06 von hjp-usenet2

On 2007-11-06 12:25, Markus S wrote:
> On 2007-11-06 5:02, Larry said:
>> in Platypus window:
>>
>> Script Type: Shell
>> Script Path: your start.sh
>>
>> the followin is the start.sh file:
>>
>> #!/bin/sh
>> #
>> # start.sh
>>
>> cd $1/Contents/Resources/
>>
>> /usr/bin/perl $1/Contents/Resources/my_perl_script.pl
>
> Thanks. Unfortunately, the $1 contains a space in my case and the cd
> command therefore fails. I would know how to deal with this within Perl
> but not on the Shell level.

Put double quotes around $1.

Or do the chdir inside the perl script.

hp

--
_ | Peter J. Holzer | It took a genius to create [TeX],
|_|_) | Sysadmin WSR | and it takes a genius to maintain it.
| | | hjp@hjp.at | That's not engineering, that's art.
__/ | http://www.hjp.at/ | -- David Kastrup in comp.text.tex