Platypus - Current Working Directory - write files

M

Markus S

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
 
K

kens

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
 
T

Tad McClellan

Markus S said:
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?
 
L

Larry

Markus S said:
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
 
B

Ben Morrow

Quoth 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

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
 
D

Dr.Ruud

Joe Smith schreef:
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.
 
T

Tad McClellan

Dr.Ruud said:
Joe Smith schreef:

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top