Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Perl calling Linux commands

by MVRS (Acolyte)
on Mar 08, 2013 at 10:13 UTC ( [id://1022378]=perlquestion: print w/replies, xml ) Need Help??

MVRS has asked for the wisdom of the Perl Monks concerning the following question:

hi Monks ,Am trying to run system command which takes input from the user

#!/usr/bin/perl use strict; print "Enter the Rast Username\n"; my $username = <>; print "Enter the Rast Password\n"; my $Password = <>; print "Enter the fasta file Name\n"; my $fasta = <>; print "Enter the Domain Name\n"; my $domain= <>; print "Enter Genetic_Code\n"; my $Genetic_code = <> ; system (qq("svr_submit_RAST_job --user "$username" --passwd "$Password +" --fasta "$fasta" --domain "$domain" --genetic_code "$Genetic_code") +);

if same job submitted as following, it works

system("svr_submit_RAST_job --user "=xxxxxx --passwd ******** --fasta seq.fasta --domain bacteria --genetic_code 11)

it works , why iam unable make with $xxxxx script please help me in solving this problem

Replies are listed 'Best First'.
Re: Perl calling Linux commands
by tobyink (Canon) on Mar 08, 2013 at 10:17 UTC
    chomp(my $username = <>); # ... etc

    See chomp.

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
Re: Perl calling Linux commands
by marto (Cardinal) on Mar 08, 2013 at 10:17 UTC

    Read the advice you got in your previous post about using chomp when reading input input from users.

Re: Perl calling Linux commands
by tmharish (Friar) on Mar 08, 2013 at 11:06 UTC

    If you had printed the system command that you were running you would have figured this out.

    Update

    Just to show what I meant consider what happens when your code is modified like so:

    my $command = qq("svr_submit_RAST_job --user "$username" --passwd "$Pa +ssword" --fasta "$fasta" --domain "$domain" --genetic_code "$Genetic_ +code") ; print "\n\n\nGoing to run the following through system:\n $command\n";
    Output
    Enter the Rast Username username Enter the Rast Password password Enter the fasta file Name filename Enter the Domain Name domainname Enter Genetic_Code geneticcode Going to run the following through system: "svr_submit_RAST_job --user "username " --passwd "password " --fasta "filename " --domain "domainname " --genetic_code "geneticcode "

    And the newlines are there for you to see, as plain as daylight.

      Additionally you need to look at tainted variables.

      Its a really bad idea to take user input and throw it to system ( or a database ) - What if the username input was:

      " || ls && 0 &&

      Of course you could replace ls with whatever exciting nefarious command you choose but thats the idea ...

Re: Perl calling Linux commands
by vinoth.ree (Monsignor) on Mar 08, 2013 at 11:07 UTC
Re: Perl calling Linux commands
by Anonymous Monk on Mar 09, 2013 at 01:26 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1022378]
Approved by tobyink
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2025-03-20 02:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (60 votes). Check out past polls.