Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert perl script from unix to windows

Status
Not open for further replies.

mo7

Programmer
Aug 1, 2008
5
CA
Problem when moving a perl script wrote on unix to windows.
This script is wrote in perl on unix machine.
open(INPUT_LINE,"-|") || exec(chdir);
$current_path = <INPUT_LINE>;
chomp($current_path);
close(INPUT_LINE);

I have a problem with "-|" when moving a perl script wrote on unix machine to windows. In the comand line, i am getting the following message:

'-' is not recognized as an internal or external command, operable program or batch file.

How can i resolve this problem. I appreciate your help.

 
Sorry for my ignorance, but what exactly does "-|" do for you on UNIX? Maybe I'll have an idea after you describe that to me.
 
Hello CJason,

There is different MODE for the open function.
if MODE is '-|', the filename is interpreted as a command which pipes output to us.
I got this explnation from this web site: Hope this can say something to you.
 
On my (FC9) Linux box, chdir is a 'command not found'. If you are just trying to get the current working directory, then there may be other ways to do this.
Perl:
my $current_path = (qx{pwd})[0];
chomp $current_path;
but I don't know what the equivalent of pwd is in Windows. I'd be surprised if Perl doesn't have a $ variable for it. Any ideas anyone?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Hello stevexff and everyone,

I don't have problem with the command chdir. Actually the chdir (in windows) is the equivalent of pwd (in unix). The problem i'm encountring is that the parameter "-|" in the open function is not recognized in windows environnement. If you put this code on a unix machine (with pwd instead of chdir) there is no problem with the parameter "-|".
The code i am talking about is written in perl language.

Here is the code:

open(INPUT_LINE,"-|") || exec(chdir);
$current_path = <INPUT_LINE>;
chomp($current_path);
close(INPUT_LINE);

ANY ONE CAN HELP ?
 
But what is that code intended to achieve? If it's to store the current directory in $current_path, you've got two good leads on how to do it. I think I'd do something like this (in both unix and windows):
Code:
$current_directory = chomp(`pwd`);
If it's to do something else, tell us about it.

Either way, don't get hung up on converting every step of the operation to windows, just find a way to get the end result you require.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Hello ChrisHunt,

I used the command getcwd. It works. Thanks for your advice of not get hunging up on converting every step.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top