Perl script doesn't open command prompt on running in Windows7 - perl

My Perl script doesn't execute at all when I press F5. In fact the command prompt also doesn't appear. Please help me as to what is wrong. The following is the Hello World script.
use 5.010;
use strict;
use warnings;
print "Hello World!\n";

The problem might be that your program runs so quickly that command prompt opens and closes faster than you can see it. To see if that's the case, and fix it if so, you can wait for user input:
print "Press ENTER to quit.\n";
scalar <>;

Related

Printing the result of the script(running in background) on the terminal

I am writing a perl script which runs another tcl script from it. The terminal doesn't print anything and waits for the tcl script to complete.
`chmod +x runme.tcl`; `./runme.tcl 2>&1`;
Can anyone please help me on how to print the results of the tcl script on the terminal instead of just waiting for it to get completed?
Thank you
system('chmod +x runme.tcl');
system('/runme.tcl 2>&1');
You can run tcl scripts directly from perl using the Tcl module without having to mess around with qx or system:
#!/usr/bin/env perl
use warnings;
use strict;
use Tcl;
Tcl->new->EvalFile("runme.tcl");
It'll share the same standard output as the perl script.
If you're using a new enough version of Tcl, you can easily create a safe interpreter to evaluate the script in case it tries to do anything nasty:
#!/usr/bin/env perl
use warnings;
use strict;
use Tcl v1.05;
my $interp = Tcl->new;
my $safeinterp = $interp->CreateSlave("safeinterp", 1);
$interp->Eval('interp share {} stdout safeinterp');
$interp->Eval('interp share {} stderr safeinterp');
$safeinterp->EvalFile("runme.tcl");
Backticks capture the output of an external command. You can write that output with a print command in front of the backticks.
`chmod +x runme.tcl`; print `./runme.tcl 2>&1`;

Writing to a text file using Perl CGI

I am using cgi to call a perl function, and inside the perl function, I want it to write something in a txt. But it's not working for now. I have tried to run the cgi script on my apache server. The cgi could print the webpage as I requied, but I can't see the file that I want it to write. Seems like the perl script is not execute by the server.
The perl script is quite simple.The file name is perl predict_seq_1.pl
#!/usr/bin/perl -w
use strict;
use warnings;
my $seq = $ARGV[0];
my $txtfile = "test.txt";
open(my $FH, '>', $txtfile);
print $FH "test $seq success\n";
close $FH;
And the cgi part, I just call it by
system('perl predict_seq_1.pl', $geneSeq);
Your CGI program is going to run by a user who has very low permissions on your system - certainly lower than your own user account on that same system.
It seems likely that one of two things is happening:
Your CGI process can't see the program you're trying to run.
Your CGI program doesn't have permission to execute the program you're trying to run.
You should check the return value from system() and look at the value of $?.
Either give system a single string, or give it individual arguments. Your script is attempting and failing to run the program perl predict_seq_1.pl, rather than having perl run the script predict_seq_1.pl.
system('perl', 'predict_seq_1.pl', $geneSeq);

Command for login history in Strawberry Perl in Windows

I am getting error i.e last is not recognized as a internal or external in cmd prompt
What I have tried:
#!/usr/bin/perl
use strict;
use warnings;
my $d=system("last");
print $d;
You can't use the last command under windows, you'll have to use something like wmic, net user or similar, depending on what info you need/want.

Simulate pressing enter key in Perl

I have following perl script which saves the output from the command into a textfile
#!/usr/bin/perl
use warnings;
use strict;
use Term::ANSIColor;
my $cmd_backupset=`ssh user\#ip 'dsmadmc -id=username -password=passwd "q backupset"' >> output.txt`;
open CMD, "|$cmd_backupset" or die "Can not run command $!\n";
print CMD "\n";
close CMD;
The output of output.txt is this:
Text Text Text
...
more... (<ENTER> to continue, 'C' to cancel)
The script is still running in the terminal and when I press enter, the output.txt file gets the extra information. However, I must press enter more than 30 times to get the complete output. Is there a way to automate the script so when the last line in output.txt is more..., it simulates pressing enter?
I have tried with Expect (couldn't get it installed) and with echo -ne '\n'
Most interactive commands, like the one you are using, accept some flag or some command to disable pagination. Sometimes, connecting their stdin stream to something that is not a TTY (e.g. /dev/null) also works.
Just glancing over IBM dsmadmc docs, I see it accepts the option -outfile=save.out. Using it instead of standard shell redirection would probably work in your case.

Why can't I run a Perl program from TextMate?

I'm following a bioinformatics text, and this represents one of my first Perl scripts. While in TextMate, this does not produce any result. Is it functioning? I added "hello world" at the bottom and I don't see that when I run the script in TextMate. What have I done wrong?
#!/usr/local/bin/perl -w
use lib "/Users/fogonthedowns/myperllib";
use LWP::Simple;
use strict;
#Set base URL for all eutils
my $utils = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils";
my $db = "Pubmed";
my $query ="Cancer+Prostate";
my $retmax = 10;
my $esearch = "$utils/esearch.fcgi?" .
"db=$db&retmax=$retmax&term=";
my $esearch_result = get($esearch.$query);
print "ESEARCH RESULT: $esearch_result\n";
print "Using Query: \n$esearch$query\n";
print "hello world\n";
Have you run other scripts successfully in TextMate? I suspect that you have an editor configuration issue (or that URL is not hittable and the script is generating an error).
Try running an even simpler script and see what happens, e.g. something like:
#!/usr/local/bin/perl -w
print "hello world\n";
Next, see if you can see error output:
#!/usr/local/bin/perl -w
warn "oh noes";
Most likely, your executing environment is not set up in the right way, i.e., TextMate does not know how to execute a Perl script and display the results to you. Have you tried running it from the shell?
Do you have /usr/local/bin/perl installed? What does which perl return at the terminal?
If your hashbang line is incorrect then when you come to run the script in TextMate you will just get an empty output window. Textmate does not give any error that it couldn't find the executable interpreter you prescribed after #! :(
Replace the first line with #!/usr/bin/env perl and it will run you login's default Perl (found in $PATH environment variable).
/I3az/