将批处理命令行设置为另一个命令行中的字符串

时间:2018-04-25 13:02:18

标签: windows batch-file cmd

正如标题所示,我试图在另一个命令行中将命令行输出设置为字符串。

示例:

  

verpatch %% ~ni %% ~xi / s desc %% ~ni / s comment %% ~ni / pv ' call jrepl   " [0-9] + [0-9] + [0-9] + [0-9] +&#34。; "" / match / s%filename%'

请注意:

call jrepl "[0-9]+.[0-9]+.[0-9]+.[0-9]+" "" /match /s %filename%

是输出的另一个命令: 1.2.3.4 [它是从文件名中提取数字的函数]

所以我需要这样的输出:

verpatch %% ~ni %% ~xi / s desc %% ~ni / s comment %% ~ni / pv 1.2.3.4

在这里,我分享了我的整个代码,以便您明白:

@ECHO OFF
SETLOCAL
set file=C:\Users\Jack\Desktop\Files\*
set dot=.
FOR %%i IN ("%file%") DO (
set filedrive=%%~di
set filepath=%%~pi
set filename=%%~ni
set fileextension=%%~xi
:: This Line is supposed to store jrepl command as a string ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
SET COMMAND="call jrepl "[0-9]+\.[0-9]+\.[0-9]+.[0-9]+" "" /match /s %filename%"
:: Extract the string and print to the screen
verpatch %%~ni%%~xi  /s desc %%~ni /s comment %%~ni /pv %COMMAND%
pause
)

pause

jrepl 是dbenham的正则表达式文本处理器批处理函数文件JREPL.BAT

这是我的第二次尝试将命令保存为变量:

@ECHO OFF
setlocal enabledelayedexpansion
set "file=C:\Users\Jack\Desktop\Files\*"
FOR %%i IN ("%file%") DO (
set filedrive=%%~di
set filepath=%%~pi
set filename=%%~ni
set fileextension=%%~xi
: Save Command Line as a variable
for /f "delims=" %%a in ('call jrepl "[0-9]+\.[0-9]+\.[0-9]+.[0-9]+" "" /match /s %%~ni') do @set theValue=%%a 
verpatch %%~ni%%~xi  /s desc %%~ni /s comment %%~ni /pv %theValue%
pause
)
pause

我有一个充满个人程序的文件夹

  

ProgramOne 1.2.3.4.exe

     

ProgramTwo 2.2.2.2.exe

     

我尝试制作一个从这些程序中提取程序名称和版本的批处理,并将它们插入到单独的命令行中,例如:

verpatch" ProgramOne 1.2.3.4.exe" / s desc ProgramOne / s评论ProgramOne / pv 1.2.3.4

1 个答案:

答案 0 :(得分:1)

试试这个,我假设你的from numpy import issubdtype from numpy import integer from numpy import floating from pandas import read_csv from shapefile import Writer # PyShp library df = read_csv('/some/file', low_memory = False) rows = df.values.tolist() # fastest access over df.iterrows() w = Writer(5, True) # This is the core of the question # I can access df[col].dtype but I didn't want to use str == str # If this can be done better than subtype check let me know for col in df: if issubdtype(df[col], integer): w.field(col, 'N', 20, 0) elif issubdtype(df[col][0], floating): w.field(col, 'F', 20, 10) else: w.field(col, 'C', 40, 0) # Alternatively (1): # from numpy import int64 # from numpy import float64 # for col in df: # if df[col].dtype.type is int64: # w.field(col, 'N', 20, 0) # elif df[col].dtype.type is float64: # w.field(col, 'F', 20, 10) # else: # w.field(col, 'C', 40, 0) # Alternatively (2): # Don't import numpy directly in namespace # for col in df: # if df[col].dtype == 'int64': # w.field(col, 'N', 20, 0) # elif df[col].dtype == 'float64': # w.field(col, 'F', 20, 10) # else: # w.field(col, 'C', 40, 0) lon = df.columns.get_loc('LON') lat = df.columns.get_loc('LAT') for row in rows: w.point(row[lon], row[lat]) w.record(*row) w.save('/some/outfile') verpatch命令都是正确的,(我从未使用过它们)

JREPL

修改

根据您提供的文件管理策略而不使用@Echo Off Set "filelocn=C:\Users\Jack\Desktop\Files" For %%A In ("%filelocn%\*.exe") Do (For /F %%B In ( 'jrepl "[0-9]+\.[0-9]+\.[0-9]+.[0-9]+" "" /match /s %%~nA') Do ( verpatch "%%A" /s desc "%%~nA" /s comment "%%~nA" /pv %%B Pause)) ,这可能对您有用:

JREPL