How to port scripts written for UNIX on windows

K

karuna

Hi

I have written nearly 70 perl scripts which run well on UNIX
platforms. But on windows(2000/03 and XP) am finding lot of problem.

I am ending up rewriting code with too much of modification.

What is the solution for this ?.

Those who know kindly reply back to me ..

Thanks
Karuna
 
B

Brian Wakem

karuna said:
Hi

I have written nearly 70 perl scripts which run well on UNIX
platforms. But on windows(2000/03 and XP) am finding lot of problem.

I am ending up rewriting code with too much of modification.

What is the solution for this ?.


Write portable code. Of course it's too late as you've already it. Do you
have any specific problems? code examples?
 
J

Jürgen Exner

karuna said:
I have written nearly 70 perl scripts which run well on UNIX
platforms. But on windows(2000/03 and XP) am finding lot of problem.

I am ending up rewriting code with too much of modification.

Do you have examples of pieces that you have to rewrite?
What is the solution for this ?.

Simple. Don't write non-portable Perl code to begin with. Doesn't help you
much now, but that is really the underlying problem.

For details please see "perldoc perlport"

jue
 
T

Tintin

karuna said:
Hi

I have written nearly 70 perl scripts which run well on UNIX
platforms. But on windows(2000/03 and XP) am finding lot of problem.

I am ending up rewriting code with too much of modification.

What is the solution for this ?.

Write portal code to start with.

Don't call external programs that can be done natively in Perl.

Use configuration files so you don't have to hardcode settings in the Perl
scripts.
 
K

karuna

Hi

Thanks for your replies
the problem is on unix suppose am using the path as "/opt/OV/bin"
on windows it becomes "C:/Prog Files/Product Name/bin"

and all scalar variables need to be enclosed with escape sequence
for eg : a variable called $BIN need to be used as \"$BIN\"
this is becomming a big pain.
IS there is any way in windows or any API is there which could solve
my problem

Or normally how perl scripts will be written which work both on unix
and
windows ...
Karuna
 
J

Jürgen Exner

karuna said:
Thanks for your replies
the problem is on unix suppose am using the path as "/opt/OV/bin"
on windows it becomes "C:/Prog Files/Product Name/bin"

Well, obviously calling external programs is not portable. Period.

"Doctor, if I do this then it hurts."
"Well, then don't do it."

Use native Perl functions or modules instead.
Or if those are custom programs for which there is no Perl equivalent, then
define those pathes in one single configuration module. Then you have to
change that one single file only.
and all scalar variables need to be enclosed with escape sequence
for eg : a variable called $BIN need to be used as \"$BIN\"

What? Why do you think so?
this is becomming a big pain.
IS there is any way in windows or any API is there which could solve
my problem

Or normally how perl scripts will be written which work both on unix
and
windows ...

Well, did you actually read the FAQ that was pointed out to you? Or did you
just thank people blindly without reading their suggestions?

jue
 
B

Brian Wakem

karuna said:
Hi

Thanks for your replies
the problem is on unix suppose am using the path as "/opt/OV/bin"
on windows it becomes "C:/Prog Files/Product Name/bin"

and all scalar variables need to be enclosed with escape sequence
for eg : a variable called $BIN need to be used as \"$BIN\"
this is becomming a big pain.


Can you give an example of where you need to do that?
 
X

xhoster

karuna said:
Hi

Thanks for your replies
the problem is on unix suppose am using the path as "/opt/OV/bin"
on windows it becomes "C:/Prog Files/Product Name/bin"

That is not a OS-specific portability problem. You would have the same
problem moving between two linux machines which had the directory installed
in different places.
and all scalar variables need to be enclosed with escape sequence
for eg : a variable called $BIN need to be used as \"$BIN\"
this is becomming a big pain.

I have no idea what you are trying to say here. Please include more perl
context in your examples.

Xho
 
T

Tintin

karuna said:
Hi

Thanks for your replies
the problem is on unix suppose am using the path as "/opt/OV/bin"
on windows it becomes "C:/Prog Files/Product Name/bin"

Either create a configuration file where you can set all the appropriate
settings, or use something like

my $path;

if ($^O =~ /Win/) {
$path = "C:/Prog Files/Product Name/bin";
}
else {
$path = "/opt/OV/bin";
}
 
B

Brian McCauley

gargoyle said:
You're using system() to run external programs? If that's the case,
maybe you can use the alternate syntax described in 'perldoc system',
like this:
system("command", "arg1", "arg2")
instead of this:
system("command arg1 arg2")

You'd hope that wouldn't you, but it is not the case. Windows joins an
resplits the list.
 
J

Joe Smith

karuna said:
I have written nearly 70 perl scripts which run well on UNIX
platforms. But on windows(2000/03 and XP) am finding lot of problem.

I am ending up rewriting code with too much of modification.

I keep two instances of perl on my WinXP PC.
1) ActiveState perl in C:\Perl\bin
2) Cygwin perl in C:\cygwin\bin (aka /usr/bin)

The second instance runs almost all of my Linux perl scripts
on Windows with no changes.
-Joe
 
K

Kjetil Skotheim

I keep two instances of perl on my WinXP PC.
1) ActiveState perl in C:\Perl\bin
2) Cygwin perl in C:\cygwin\bin (aka /usr/bin)

The second instance runs almost all of my Linux perl scripts
on Windows with no changes.
-Joe


Yes, cygwin is the great saviour for porting unix stuff to
windows. Not just perl, but also bash and other stuff.

http://www.cygwin.com/

CygWin will also make i possible to use: perl -MCPAN -e shell
to install things (together with gcc as well) instead of the
activestate way, which is good, but many cpan modules are missing...


I recommend CygWin for everyone who knows a bit of unix/linux,
and who isn't happy at all with the crummy old black CMD (DOS)
command line window (that is everyone, I suppose), but don't
want to replace Windows with Linux eiher.

Tip:
Remember to install rxvt in cygwin. It will give you a white
re-sizeable "bash-window" without going for the full X Windows package(s)
and xterm. In the right-click-properties on a shortcut to rxvt on your
desktop, use this or a similar thing as "target":

C:\cygwin\bin\rxvt.exe -fn -12 -geometry 100x42 -sl 3000 -e bash -ls
 

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

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top