Run perl script, with command-line options


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run perl script, with command-line options
# 1  
Old 03-16-2011
Run perl script, with command-line options

Hello everyone,

I have a perl script which takes various command line options from user like :
Code:
test.pl -i <input_file> -o <output_file> -d <value> -c <value>

Now I have multiple input files in a directory:

Code:
<input_file_1>
<input_file_2>
<input_file_3>
<input_file_4>
.....
....
...
..
.

I am trying to run this perl script for all the input files, in a unix shell script. The problem I am facing is that the program is not able to find <output_file> in the directory (obviously because it is defined by user with -o option). It gives the following error:

Code:
IOError: [Errno 2] No such file or directory: <output_file>

Any suggestions?
# 2  
Old 03-16-2011
You haven't posted your code so I can't see what's wrong with it. You'd like it to create the file, not just open it, right?
# 3  
Old 03-16-2011
yes, I would like to create an output file. My code is as follows :

Code:
for i in $(ls test/*.input)
do
        new = ${i%%.input}
        test.pl -i $new.input.xml -o output_$new -x $new.info -d 86
done

$new.input.xml ---> Input files in my directory.
$new.info ----> corresponding info file for each input file.
-o output_$new ---> should return output file for each input file.

Last edited by ad23; 03-16-2011 at 12:43 PM..
# 4  
Old 03-16-2011
Have a look at
Code:
perldoc Getopt::Long

# 5  
Old 03-16-2011
Your perl script has become shell scripting + python. Who's calling the which with the what now?
# 6  
Old 03-16-2011
Sorry, its test.pl !
# 7  
Old 03-16-2011
Okay. You still need to post the content of the perl script then.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Run script as root from command line

I have a script (ksh) that has permissions 775 and owned by root.system. This script takes the parameter of a full file name and chmods the file to 666 and changes ownership to user smith.staff. ex: modify_file.ksh /home/smith/filea modify_file.ksh has 775 and root.system ownership. The... (1 Reply)
Discussion started by: mlacriola
1 Replies

2. Shell Programming and Scripting

Reading command line options from bash script

I have the following code and I am calling it using ./raytrac.bash -u and getting problems. For some reason opt_usage is still 0. opt_usage=0 iarg=0 narg=$# while (($iarg < $narg)) do (( iarg = $iarg + 1 )) arg=$argv usrInputFlag=`echo $arg | awk '/=/ {print 1}; ! /=/... (22 Replies)
Discussion started by: kristinu
22 Replies

3. Shell Programming and Scripting

Run perl command in script[solved]

Hi all, When I put the Perl command in a script, I got error. system("perl -pi -e 's@words@words@g' myFile"); The error is: Unrecognized character \x8A; marked by <-- HERE after دت مد�<-- HERE near column 15 at -e line 1. Thanks in advance. ---------- Post updated at 06:30 AM... (0 Replies)
Discussion started by: Lham
0 Replies

4. Shell Programming and Scripting

awk script file command line options

Being new to awk I have a really basic question. It just has to be in the archives but it didn't bite me when I went looking for it. I've written an awk script, placed it in a file, added the "#!/usr/bin/awk -f" at the top of the script and away I go. "% myAwk <inputfile>" gives me exactly what... (2 Replies)
Discussion started by: tomr2k
2 Replies

5. Shell Programming and Scripting

perl/unix: script in command line works but not in perl

so in unix this command works works and shows me a list of directories find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt but when i try running a perl script to run this command my $query = 'find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt';... (2 Replies)
Discussion started by: kpddong
2 Replies

6. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

7. Windows & DOS: Issues & Discussions

Cannot run command line scripts in perl or gawk

I originally posted this to a different forum (I am a new Perl user) and realized the error so I will ask here. I am on a WindowsXP machine trying to run perl and gawk scripts from the command line. I have perl and gawk installed and environment set to C:\perl\bin and cannot get a script to... (2 Replies)
Discussion started by: 10000springs
2 Replies

8. Shell Programming and Scripting

Using perl to get options from command line

Hi all, I want to get options from command line by perl. usage() options: -h Show this help message and exit -t Name of tester --timeout Set the timeout -l ... (1 Reply)
Discussion started by: Damon_Qu
1 Replies

9. Solaris

How to run a script with options

I have a script name as psin_install_i3fp.sh I need to run this script like ./psin_install_i3fp.sh step2 What this step2 represents? my script contains data: #!/bin/ksh mkdir logs >> /dev/null 2>&1 ./infra/bin/psin_stop_ba.sh mv ./psin_start_ba.sh... (2 Replies)
Discussion started by: pmrajesh21
2 Replies

10. Shell Programming and Scripting

Run the command inside perl script

I have a command which will run fine in a unix command prompt. Can you tell how to interprete this command inside perl script...... The command is : perl -pe 's/(\|333\}.*)\}$/$1|1.6}/' FIA.txt This will search for the number 333 and appends 1.6 at the end of that line....... (1 Reply)
Discussion started by: vinay123
1 Replies
Login or Register to Ask a Question