I want to get the full computer name using the ActiveState Perl on windows .
Actually i can get that using the "hostname" command, but i want to have the output of the "hostname" command stored in some variable using perl. And i wan to use that variable in my script.
Is it possibel to write a script which will store the return value of the command executed on the command prompt and how ???
Kindly help
6 29749
You have posted this in the Articles section. I am moving it to the Perl forum.
ADMIN
I don't understand your question well enough to answer it. You can store return values various ways: in variables or in a database or in a text file. If the value is only needed for the life of the script store it in a variable, if the value needs persistence, store it in a file or database or look into the Storable module, which comes with perl.
prn 254
Expert 100+
I'm guessing that what ajays means is that he doesn't know how to capture the information that "hostname" outputs. OTOH, I might also note that "hostname" does not reliably put out an FQDN (fully qualified domain name). Assuming that ajays is using the Active State Perl (that's by far the most common Perl for windows), he should have the Net:: Domain module available. See http://www.xav.com/perl/site/lib/Net/Domain.html for specs. This may prove more reliable than just "hostname".
Try: - use strict;
-
use Net::Domain qw (hostname hostfqdn hostdomain);
-
-
my $hostname = `hostname`;
-
print "my hostname is $hostname\n";
-
-
my $fqdn = hostfqdn();
-
print "my fqdn is $fqdn\n";
-
and see what you get. On my windows box, I get: - my hostname is phobos
-
my fqdn is phobos.bsu.edu
-
HTH,
Paul
You're probably right Paul. Hopefully he comes back and reads your reply.
I stumbled into this topic years later.
Just want to point out that prn's example appears to work, but does not do that it suggests.
prn>> use Net::Domain qw (hostname hostfqdn hostdomain);
prn>> my $hostname = `hostname`;
The first line 'activates' the hostname function,
But the second name executes (back-tick / qx) a command using the string 'hostname'... which typically gives the same result, and does appear to work, but less reliably so.
Just drop the back-ticks and it will use the function, not a fresh process.
Cheers,
Hein
RonB 589
Expert Mod 512MB
Hein,
I believe you misinterpreted what Paul was demonstrating.
The OP was asking about how to capture the output of the system's hostname command. Paul was demonstrating the difference between doing that and using the hostfqdn() function from the module. It would have been more clear if he didn't include/import the hostname() and hostdomain() functions in the use statement.
Here's an updated (corrected?) version. -
#!/usr/bin/perl
-
-
use warnings;
-
use strict;
-
use Net::Domain qw(hostname hostfqdn);
-
-
my $hostname = `hostname`;
-
print "my hostname is $hostname\n";
-
-
my $fqdn_hostname = hostname();
-
print qq(my "fqdn" hostname is $fqdn_hostname\n\n);
-
-
my $fqdn = hostfqdn();
-
print "my fqdn is $fqdn\n";
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Johnson Bruno |
last post by:
Hi,
I want my perl script to get date and time of another computer
which is connected by LAN.The OS is Win 2000.
I tried this , but did not work.
$file="\\\\P418\\test\\get.cmd";...
|
by: dsclements |
last post by:
>Description:
I'm running mysql in a 3 server configuration, with 2 servers being slaves to the first. I'm running vpopmail, which means a connection every incoming mail and every check. I woke up...
|
by: Xah Lee |
last post by:
Split File Fullpath Into Parts
Xah Lee, 20051016
Often, we are given a file fullpath and we need to split it into the
directory name and file name. The file name is often split into a core...
|
by: vicky |
last post by:
SUMMARY:
THREE YEARS of and continuing MENTAL TORTURE, TERRORISM, SADISM and
BLATANT human rights violations by FBI SADISTS and PERVERTS.
Please SAVE this post on your hard disks or email...
|
by: Jason Reichenbach |
last post by:
I've GOT to be missing something painfully obvious, here...
I need to programmatically get the full human name of the current user on a
local system, the same system upon which the app is...
|
by: Xah Lee |
last post by:
The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully
Functional Notations
Xah Lee, 2006-03-15
Let me summarize: The LISP notation, is a functional notation, and is
not a...
|
by: Sridhar |
last post by:
Hi,
I have a web form where it has a <input type=file id=file1> control. I
have an Upload button to upload the file. WHen I click on browse and select
one file, it is showing the full file path...
|
by: Chung Leong |
last post by:
Here's a short tutorial on how to the OLE-DB extension to access
Windows Indexing Service. Impress your office-mates with a powerful
full-text search feature on your intranet. It's easier than you...
|
by: cnsabar |
last post by:
Hi.,
I am using the following code to terminate the any process by giving the process name as input...
use Win32::Process::List;
use Win32::OLE;
$Win32::OLE::Warn = 3;
$P =...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |