HWZ Forums

Login Register FAQ Mark Forums Read

Scripting to run command line tools

Like Tree2Likes
  • 2 Post By davidktw
Reply
 
LinkBack Thread Tools
Old 11-07-2018, 11:58 AM   #1
Senior Member
 
Join Date: Jul 2009
Posts: 710
Scripting to run command line tools

I have a CSV file containing data used to invoke a command line tool.

Example of CSV:

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

The command line would look like this:

process_data.exe -name "john" -value 1 -"line_0001.dat"

... repeat ...

process_data.exe -name "elizabeth" -value 8 -"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? )

`process_data.exe -name $name -value $value -o $outfile`
PowerShell?

Start-Process '$EXE -name "$name" -value "$VALUE" -o "$OUTFILE"'
Python?
os.system('process_data.exe -name "' + name + '" -value ' + value + ' -o "' + outfile + '"')
Not on Linux, so discounting Bash scripting.
u0206397 is offline   Reply With Quote
Old 11-07-2018, 12:15 PM   #2
Supremacy Member
 
davidktw's Avatar
 
Join Date: Apr 2010
Posts: 9,312
You can try activestate perl or gawk on windows

perl -ne '$a=split /,/;' < input.csv
For perl, you can do this
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")'
peterchan75 and u0206397 like this.

Last edited by davidktw; 11-07-2018 at 02:27 PM..
davidktw is online now   Reply With Quote
Old 12-07-2018, 10:45 AM   #3
Senior Member
 
Join Date: Jul 2009
Posts: 710
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.
u0206397 is offline   Reply With Quote
Old 12-07-2018, 10:54 AM   #4
Supremacy Member
 
davidktw's Avatar
 
Join Date: Apr 2010
Posts: 9,312
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.
That is the packaging name. The code still uses :: as the namespace separator.
davidktw is online now   Reply With Quote
Reply
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. Forum members and moderators are responsible for their own posts.

Please refer to our Terms of Service for more information.


Thread Tools

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On