Solved

unix-like in-command execution?

Posted on 2015-01-22
3
166 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 33

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 53

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

790 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