473,405 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Get full computer name using Perl

7
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
May 10 '07 #1
6 29749
MMcCarthy
14,534 Expert Mod 8TB
You have posted this in the Articles section. I am moving it to the Perl forum.

ADMIN
May 10 '07 #2
KevinADC
4,059 Expert 2GB
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.
May 10 '07 #3
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:
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use Net::Domain qw (hostname hostfqdn hostdomain);
  3.  
  4. my $hostname = `hostname`;
  5. print "my hostname is $hostname\n";
  6.  
  7. my $fqdn = hostfqdn();
  8. print "my fqdn is $fqdn\n";
  9.  
and see what you get. On my windows box, I get:

Expand|Select|Wrap|Line Numbers
  1. my hostname is phobos
  2. my fqdn is phobos.bsu.edu
  3.  
HTH,
Paul
May 11 '07 #4
KevinADC
4,059 Expert 2GB
You're probably right Paul. Hopefully he comes back and reads your reply.
May 11 '07 #5
HeinV
1
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
Oct 31 '13 #6
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.
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use warnings;
  4. use strict;
  5. use Net::Domain qw(hostname hostfqdn);
  6.  
  7. my $hostname = `hostname`;
  8. print "my hostname is $hostname\n";
  9.  
  10. my $fqdn_hostname = hostname();
  11. print qq(my "fqdn" hostname is $fqdn_hostname\n\n);
  12.  
  13. my $fqdn = hostfqdn();
  14. print "my fqdn is $fqdn\n";
Oct 31 '13 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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";...
0
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...
3
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...
14
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...
7
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...
23
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...
2
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...
0
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...
2
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 =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...
0
jinu1996
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...
0
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.