Solved

unix-like in-command execution?

Posted on 2015-01-22
3
159 Views
Last Modified: 2015-01-23
Hi,

The following DOS batch file snippet cycles through file names in files.txt and processes them with a python script (which I didn't write).

for /F "usebackq delims=" %%x in ("files.txt") do (
  set line=%%x
  if not "!line:~0,1!"=="'" echo Passed TEST: %%x
  if not "!line:~0,1!"=="'" (
     echo "Working on: " %%x   ">>>>>>>>>>>>>>>>>>>>>"
     python mypy.py -u myuser -p mypwd %%x
  )
)

Open in new window

The Python program mypy.py now takes multiple arguments (%%x's).  Is there a way to emulate Unix's `cat filename` in DOS to let %%x be a space separated list of filenames, and then the python is executed?

e.g. If files.txt contained
f1.txt
f2.txt

as it stands now, the python command resolves to:
python mypy.py -u myuser -p mypwd f1.txt
and then
python mypy.py -u myuser -p mypwd f2.txt

I want it to resolve to:
python mypy.py -u myuser -p mypwd f1.txt f2.txt

Can this be done in DOS batch?

Thanks!
0
Comment
Question by:ugeb
3 Comments
 
LVL 5

Assisted Solution

by:R. Toby Richards
R. Toby Richards earned 100 total points
ID: 40564457
Have you tried any bash emulators for Windows? Cygwin is the most popular. You could also install cat.exe (and more if you wish) from the Windows port of the GNU core utilities.
0
 
LVL 32

Accepted Solution

by:
ste5an earned 400 total points
ID: 40564471
E.g.

@Echo Off

SetLocal EnableDelayedExpansion

Set SOURCE_FILE=C:\Temp\files.txt
Set PARAMETERS=

For /F "usebackq delims=" %%X In ( %SOURCE_FILE% ) Do (
	Set PARAMETERS=!PARAMETERS! %%X
)

Echo %PARAMETERS%

EndLocal

Open in new window

0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 40564675
@echo off
setlocal EnableDelayedExpansion

set Files=
for /F "usebackq delims=" %%x in ("files.txt") do (
  set line=%%x
  if "!line:~0,1!" NEQ "'" (
     echo Passed TEST: %%x
     set Files=!Files! %%x
  )
)

if "%Files%" NEQ "" (
   echo "Working on: " %Files%   ">>>>>>>>>>>>>>>>>>>>>"
   python mypy.py -u myuser -p mypwd %Files%
)

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now