Scripting to run command line tools

u0206397

Senior Member
Joined
Jul 15, 2009
Messages
764
Reaction score
0
I have a CSV file containing data used to invoke a command line tool.

Example of CSV:

PHP:
name,value
john,1
robert,2
michael,3
william,4
patricia,5
jennifer,6
linda,7
elizabeth,8


The command line would look like this:

PHP:
process_data.exe -name "john" -value 1 -o "line_0001.dat"

... repeat ...

process_data.exe -name "elizabeth" -value 8 -o "line_0008.dat"

What is the easiest/elegant way to repeatedly execute a Windows command line program and vary the input parameters and output file name, hopefully without installing any complicated run time or interpreter environment?

Normal batch file (.bat and .cmd) can't seem to parse and loop a CSV file easily.

Perl? (interpolate the command line string with parameters and use backtick operator? )

Code:
`process_data.exe -name $name -value $value -o $outfile`

PowerShell?

Code:
Start-Process '$EXE -name "$name" -value "$VALUE" -o "$OUTFILE"'

Python?
Code:
os.system('process_data.exe -name "' + name + '" -value ' + value + ' -o "' + outfile + '"')

Not on Linux, so discounting Bash scripting.
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,550
Reaction score
1,302
You can try activestate perl or gawk on windows

Code:
perl -ne '$a=split /,/;' < input.csv

For perl, you can do this
Code:
perl -ne '@a=split /,/; system("process_data", "-name", $a[0], "-value", "-o", sprintf("line_%04d.dat", $a[1])) unless ($a[0] != "name" and $a[1] != "value")'
 
Last edited:

u0206397

Senior Member
Joined
Jul 15, 2009
Messages
764
Reaction score
0
Giving ActivePerl a spin today.

I notice that the way PPM names their package is slightly different from CPAN. Using a hypen ( - ) instead of a double colon ( :: ). E.g. Data-Dumper (PPM) instead of Data:: Dumper (CPAN).

Not sure if this means any changes required in the code. Will try. :s11:
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,550
Reaction score
1,302
Giving ActivePerl a spin today.

I notice that the way PPM names their package is slightly different from CPAN. Using a hypen ( - ) instead of a double colon ( :: ). E.g. Data-Dumper (PPM) instead of Data:: Dumper (CPAN).

Not sure if this means any changes required in the code. Will try. :s11:

That is the packaging name. The code still uses :: as the namespace separator.
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top