Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

unix-like in-command execution?

Posted on 2015-01-22
3
Medium Priority
?
172 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 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 36

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 59

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 Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

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

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
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

971 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