Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

unix-like in-command execution?

Posted on 2015-01-22
3
Medium Priority
?
171 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 400 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 35

Accepted Solution

by:
ste5an earned 1600 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 57

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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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…
Suggested Courses

730 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