Solved

unix-like in-command execution?

Posted on 2015-01-22
3
170 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 34

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 56

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
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…

615 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