Perl

Moderators: Jonathan
Number of threads: 1259
Number of posts: 3644

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
SHELL Posted by generalen on 30 Sept 2004 at 11:32 AM
Hi Iam writing a shell who are going to work under UNIX. I have come so far that I now wcan list directories. What should I write so that the shell starts from my homefolder?? like C:\.. ??

Another question...Whatr shhould I write to execute a program..

Help please...

/ Thanks
Report
Re: SHELL Posted by Jonathan on 4 Oct 2004 at 2:20 PM
: Hi Iam writing a shell who are going to work under UNIX. I have come so
: far that I now wcan list directories.
Does this mean you've already solved the problem in your post "Make prompt" for yourself?

: What should I write so that the shell starts from my homefolder?? like
: C:\.. ??
You can often find information like this in the environment data (in %ENV). Run this script from the command line:-

print "$_=$ENV{$_}\n" for sort keys %ENV;

To see what you get. Entries of obvious interest:-

HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\Jonathan
USERPROFILE=C:\Documents and Settings\Jonathan

You'd get at these, for example, by using $ENV{'USERPROFILE'}. So to change to that directory you'd do:-
chdir $ENV{'USERPROFILE'};
In your script. Note that this is a bit Win32 specific. But the home directroy on a Linux/UNIX box will generally also be in the environment variables (as just HOME, usually). You can check the OS by looking at the $^O variable - it equals 'MSWin32' under Windows.

: Another question...Whatr shhould I write to execute a program..
:
Depends. Look up the system and exec (maybe used in conjunction with fork) functions. Backticks are also useful if you want to capture the output of a program.
my $pingresp = `ping 127.0.0.1`;

Jonathan

###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.