Riverstorm
Posts: 4
Joined: Tue Aug 26, 2014 5:54 pm

Running a perl script with parameters in a file

Tue Aug 26, 2014 5:59 pm

I've been trying to figure out if it's possible to run a perl script with parameters from a "batch" file so I don't have to type the whole command every time. I tried several things but I can't seem to figure it out. Here's the command. Is it possible to put it into like an executable file or batch file to run if that makes sense? It's a scraper that associates screenshots with games. Any help would be greatly appreciated. Thank you.

perl mameGenXml.pl -rompath /home/pi/mame4all/roms/ -mode mame -extension zip > gamelist.xml

User avatar
DougieLawson
Posts: 38883
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Running a perl script with parameters in a file

Tue Aug 26, 2014 6:07 pm

Wrap a shell script round it.

Code: Select all

#!/bin/bash

/usr/bin/perl mameGenXml.pl -rompath /home/pi/mame4all/roms/ -mode mame -extension zip > gamelist.xml
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Riverstorm
Posts: 4
Joined: Tue Aug 26, 2014 5:54 pm

Re: Running a perl script with parameters in a file

Tue Aug 26, 2014 9:10 pm

Ok, I will give that a try. Should I also add the full path to the MameGenXml.pl part of the command (i.e. - /home/pi/genScript/mameGenXml.pl) or is that not needed or is it good practice to do it?

User avatar
DougieLawson
Posts: 38883
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Running a perl script with parameters in a file

Tue Aug 26, 2014 9:14 pm

It depends how you're planning to run the script. If you're in a normal shell you'll inherit the normal environment, if you're running from crontab you run in a limited environment. It can be a good idea to include full paths.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Riverstorm
Posts: 4
Joined: Tue Aug 26, 2014 5:54 pm

Re: Running a perl script with parameters in a file

Tue Aug 26, 2014 9:47 pm

Ok, I don't quite understand that but I tried it both ways with the path added and without but I get the same error from the script with a different path. I am in the directory where all the files are located too.

It does run fine outside the file just from a shell. I also made it an executable with chmod +x mame (mame is the file I created).

readdir() attempted on invalid dirhandle DIR at /home/pi/genScript/mameGenXml.pl line 51.
closedir() attempted on invalid dirhandle DIR at /home/pi/genScript/mameGenXml.pl line 52.

readdir() attempted on invalid dirhandle DIR at mameGenXml.pl line 51.
closedir() attempted on invalid dirhandle DIR at mameGenXml.pl line 52.

Do I need to enclose the parameters in quotes or something?

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: Running a perl script with parameters in a file

Tue Aug 26, 2014 10:26 pm

Sounds like there's a bug in the mameGenXml.pl script - it's not checking to see if the directory exists before opening it (which is why you're getting the 'invalid dirhandle' errors). Double-check the paths you're giving as arguments to the perl script actually exist.

Riverstorm
Posts: 4
Joined: Tue Aug 26, 2014 5:54 pm

Re: Running a perl script with parameters in a file

Wed Aug 27, 2014 10:51 pm

Thanks Dougie and Andrew, the command worked perfectly and I also did have a typo in the path. I really appreciate the help as it will save a ton of keystrokes! :)

Return to “Beginners”