需要帮助从xml中提取数据并将其传递给批处理文件变量...
我似乎无法获得所需的数据,并且能够将其传递给批量变量。
我需要从TAGID中提取“AH0417”.... Catch 22-此文件更改TAGID / PHASEID / BOXID
因此它们很少相同...如果我将delims更改为
,我可以提取一个特定文件for /f "tokens=7,18-21* delims=^<![CDT[^>]] " %%a in ('find /I /N "<PHASEID>"^<Config.xml') do (
set a=%%a
)
echo %a%
那就是我现在使用所有不同的delims和/或令牌方法,如果我使用skip = 3就会导致意外情况]
任何帮助都会很出色,我整个星期都在工作,并在网上寻求帮助,仍然没有回复......我不知道这是不是很难或不可能,但我知道它可能,我需要一双合适的眼睛看着这个哈哈。提前感谢任何帮助...
<?xml version="1.0" encoding="UTF-16"?>
-<root>-<CONFIG>-<TAGID>
<![CDATA[AH0417]]>
</TAGID>-<DATETIMESTAMP>
<![CDATA[9/18/2012 4:59:08 PM]]>
</DATETIMESTAMP>-<SYSTYPE>
<![CDATA[PTWS]]>
</SYSTYPE>-<PHASEID>
<![CDATA[WJFKB02229001]]>
</PHASEID>-<BOXID>
<![CDATA[D]]>
</BOXID></CONFIG></root>
我使用了许多与令牌和delim的不同组合,但我得到空白%PhaseID%或者我得到数字“2”而不是实际数据。 这就是我想要做的......
REM ***************************************(PTLS)********************************************************
:PTLSsetup
sET sOURCE=%HOMEDRIVE%\ULLSA\PHASE\PTLS\DATA\XML
rem Extract XML to Batch
rem for /f "skip=3 tokens=* delims=[" %%G IN (C:\Ullsa\phase\ptls\data\xml\Config.xml) Do (
rem Set Serial=%%G
rem Set PhaseID=%%H
rem Set BoxID=%%I
rem )
rem echo %serial%
rem echo %PhaseID%
rem echo %BoxID%
这是完整的脚本.....
mode con:cols=70 lines=25
rem Created by (ROBERT)
color 0c
for /f "tokens=2-4 delims=/ " %%a in ('date /t') do set year=%%c
for /f "tokens=2-4 delims=/ " %%a in ('date /t') do set month=%%a
for /f "tokens=2-4 delims=/ " %%a in ('date /t') do set day=%%b
set today=%day%-%month%-%year%
echo %today%
rem **************************(LOG CREATION)************************************************
md c:\zMigrate\Backup
set currentd=C:\zMigrate\Backup
ping -n 6 127.0.0.1 >nul
CLS
echo.
set D=%date% %time%
set T=%time%
echo ****************************************** >>%currentd%\%today%.TXT
echo %Date% ---------------------^> Log Created on %computername% >>%currentd%\%today%.TXT
echo ****************************************** >>%currentd%\%today%.TXT
echo LOG CREATED IN %currentd%\%today%.TXT
echo LOG CREATED FROM %currentd% >>%currentd%\%today%.TXT
echo ****************************************** >>%currentd%\%today%.TXT
cls
rem ******************************(MENU)****************************************************
:Menu
echo *******************
IF EXIST "C:\ULLSA\PHASE\PTLS" ECHO PTLS IS INSTALLED
IF ERRORLEVEL 1 ECHO PTLS NOT INSTALLED
IF EXIST "C:\ULLSA\PHASE\PTWS" ECHO PTWS IS INSTALLED
IF ERRORLEVEL 1 ECHO PTWS NOT INSTALLED
echo *******************
IF EXIST "C:\ULLSA\PHASE\PTLS" ECHO %T% PTLS IS INSTALLED >>%currentd%\%today%.TXT
IF ERRORLEVEL 1 ECHO %T% PTLS NOT INSTALLED >>%currentd%\%today%.TXT
IF EXIST "C:\ULLSA\PHASE\PTWS" ECHO %T% PTWS IS INSTALLED >>%currentd%\%today%.TXT
IF ERRORLEVEL 1 ECHO %T% PTWS NOT INSTALLED >>%currentd%\%today%.TXT
echo.
echo.
echo.
echo.
echo.
echo WHAT TYPE WORKSTATION IS THIS?
echo.
echo *NOTE* THIS UTILITY WILL PHASE MIGRATION FILES!!!
echo.
echo.
ECHO 1: PTLS (Phase Team Leader Station)
echo.
ECHO 2: PTWS (Phase Team Workers Station)
echo.
ECHO 0: Leave Program
ECHO.
SET /p choice=Enter a number [0,1,2]:
if /i [%choice%]==[0] endlocal&goto end
if [%choice%]==[] goto Menu
if [%choice%]==[1] goto PTLS
if [%choice%]==[2] goto PTWS
ECHO Unrecognized entry. Please try again.
goto Menu
REM ***************************************(TYPE CHECK)**************************************************
:PTLS
cls
ECHO *************************
echo ***Starting PTLS Check***
ECHO *************************
echo %T% ***Starting PTLS Check*** >>%currentd%\%today%.TXT
PING -n 3 127.0.0.1>nul
CLS
set PTLSDATA="C:\ULLSA\PHASE\PTLS\DATA\XML"
if exist %ptlsdata%\config.xml goto PTLSsetup
if errorlevel 1 goto PTLSFail
:PTLSFAIL
cls
echo ********************************************************
echo **PTLS XML DOES NOT EXIST, ENSURE PTLS IS INSTALLED...**
echo ********************************************************
echo %T% **PTLS XML DOES NOT EXIST, ENSURE PTLS IS INSTALLED...** >>%currentd%\%today%.TXT
ping -n 6 127.0.0.1>nul
goto Menu
:PTWS
cls
ECHO *************************
echo ***Starting PTWS Check***
ECHO *************************
echo %T% ***Starting PTWS Check*** >>%currentd%\%today%.TXT
PING -n 3 127.0.0.1>nul
CLS
set PTWSDATA="C:\ULLSA\PHASE\PTwS\DATA\XML"
if exist %ptwsdata%\config.xml goto PTWSsetup
if errorlevel 1 goto PTWSFail
:PTWSFAIL
cls
echo ********************************************************
echo **PTWS XML DOES NOT EXIST, ENSURE PTWS IS INSTALLED...**
echo ********************************************************
echo %T% PTWS XML DOES NOT EXIST, ENSURE PTWS IS INSTALLED. >>%currentd%\%today%.TXT
ping -n 6 127.0.0.1>nul
goto Menu
REM ***************************************(PTLS)********************************************************
:PTLSsetup
sET sOURCE=%HOMEDRIVE%\ULLSA\PHASE\PTLS\DATA\XML
rem Extract XML to Batch
rem for /f "skip=3 tokens=* delims=[" %%G IN (C:\Ullsa\phase\ptls\data\xml\Config.xml) Do (
rem Set Serial=%%G
rem Set PhaseID=%%H
rem Set BoxID=%%I
rem )
rem echo %serial%
rem echo %PhaseID%
rem echo %BoxID%
echo **********************************
echo ***Setting up PhaseID and BoxID***
echo **********************************
echo %T% ***Setting up PhaseID and BoxID*** >>%currentd%\%today%.TXT
ping -n 4 127.0.0.1>nul
CLS
rem extract xml data to phaseid and boxid
Set PhaseID=PhaseID
Set BoxID=BoxID
set Pbackup=%HOMEDRIVE%\Backup\%PhaseID%
set Bbackup=%HOMEDRIVE%\Backup\%PhaseID%\%BoxID%
Set Backup=%HOMEDRIVE%\Backup\%PhaseID%\%BoxID%
ping -n 4 127.0.0.1>nul
goto PTLSBackup
:PTLSBackup
if exist %backup% goto ptlsxfr
if errorlevel 1 goto ptlsmd
:ptlsmd
MD %backup% >>%currentd%\%today%.TXT
echo %T% Creating Phase Folder >>%currentd%\%today%.TXT
echo %T% Creating Box Folder >>%currentd%\%today%.TXT
echo Creating Destination
ping -n 6 127.0.0.1>nul
if exist %Bbackup% goto ptlsxfr
if errorlevel 1 echo %T% CAN^'T CREATE DESTINATION >>%currentd%\%today%.TXT
ping -n 3 127.0.0.1>nul
CLS
goto menu
:ptlsxfr
echo ****************************
echo ***Created Destination***
echo ****************************
echo %T% ***Created Destination*** >>%currentd%\%today%.TXT
PING -n 3 127.0.0.1>nul
CLS
echo ****************************
echo ***Starting PTLS Transfer***
echo ****************************
echo %T% ***Starting PTLS Transfer*** >>%currentd%\%today%.TXT
ping -n 3 127.0.0.1>nul
CLS
echo.
cacls "%sOURCE%" /T /E >>%currentd%\%today%.TXT
cacls "%backup%" /T /E >>%currentd%\%today%.TXT
CLS
echo Transfering Phase: %phaseID% Box: %BoxID%
echo %T% Transfering Phase: %phaseID% Box: %BoxID% >>%currentd%\%today%.TXT
xcopy "%sOURCE%\*" "%backup%\" /Y /E /H /V /G >>%currentd%\%today%.TXT
CLS
ECHO Transfer Complete
ECHO %T% Transfer Complete >>%currentd%\%today%.TXT
ping -n 3 127.0.0.1>nul
EXIT
REM ***************************************(PTWS)********************************************************
:PTWSsetup
rem Extract XML to Batch
rem place code or cmd to call to vbs
echo **********************************
echo ***Setting up PhaseID and BoxID***
echo **********************************
echo %T% ***Setting up PhaseID and BoxID*** >>%currentd%\%today%.TXT
ping -n 4 127.0.0.1>nul
CLS
rem extract xml data to phaseid and boxid
Set PhaseID=PhaseID
Set BoxID=BoxID
set Pbackup=%HOMEDRIVE%\Backup\%PhaseID%
set Bbackup=%HOMEDRIVE%\Backup\%PhaseID%\%BoxID%
Set Backup=%HOMEDRIVE%\Backup\%PhaseID%\%BoxID%
sET sOURCE=%HOMEDRIVE%\ULLSA\PHASE\PTWS\DATA\XML
goto PTWSBackup
:PTWSBackup
if exist %backup% goto ptWsxfr >>%currentd%\%today%.TXT
if errorlevel 1 goto ptWsmd >>%currentd%\%today%.TXT
:ptWsmd
MD %backup% >>%currentd%\%today%.TXT
echo %T% Creating Phase Folder >>%currentd%\%today%.TXT
echo %T% Creating Box Folder >>%currentd%\%today%.TXT
echo Creating Destination
ping -n 6 127.0.0.1>nul
if exist %Bbackup% goto ptWsxfr
if errorlevel 1 echo %T% CAN^'T CREATE DESTINATION >>%currentd%\%today%.TXT
ping -n 3 127.0.0.1>nul
goto menu
:ptWsxfr
echo ****************************
echo ***Created Destination***
echo ****************************
echo %T% ***Created Destination*** >>%currentd%\%today%.TXT
PING -n 2 127.0.0.1>nul
cls
echo ****************************
echo ***Starting PTWS Transfer***
echo ****************************
echo %T% ***Starting PTWS Transfer*** >>%currentd%\%today%.TXT
ping -n 3 127.0.0.1>nul
CLS
echo.
cacls "%sOURCE%" /T /E >>%currentd%\%today%.TXT
cacls "%backup%" /T /E >>%currentd%\%today%.TXT
CLS
echo Transfering Phase: %phaseID% Box: %BoxID%
echo %T% Transfering Phase: %phaseID% Box: %BoxID% >>%currentd%\%today%.TXT
xcopy "%sOURCE%\*" "%backup%\" /Y /E /H /V /G >>%currentd%\%today%.TXT
ECHO Transfer Complete
ECHO %T% Transfer Complete >>%currentd%\%today%.TXT
ping -n 3 127.0.0.1>nul
EXIT
答案 0 :(得分:0)
IT完成!!!!!与POWERSHELL的关系,它很容易! 将Powershell的输出恢复为批处理文件变量时出现问题....
将Powershell输出提取到批处理文件变量....
我写了3个单独的PS脚本,所以我可以稍后在其他脚本中单独使用它们....
PowerShell脚本TAG.PS1
[CODE]
[xml]$config1=get-content .\config.xml
foreach($tagid in $config1.root.config.tagid)
{
write-output $tagid.innertext
}
[/ CODE]
PowerShell脚本PHASE.PS1
[CODE]
[xml]$config1=get-content .\config.xml
foreach($phaseid in $config1.root.config.phaseid)
{
write-output $phaseid.innertext
}
[/ CODE]
PowerShell脚本BOX.PS1
[CODE]
[xml]$config1=get-content .\config.xml
foreach($Boxid in $config1.root.config.Boxid)
{
write-output $Boxid.innertext
}
[/ CODE]
Windows批处理文件* .bat
[CODE]
for /f "tokens=1" %%a in ('powershell.exe .\TAG.ps1') do set tagid=%%a
for /f "tokens=1" %%a in ('powershell.exe .\PHASE.ps1') do set phaseid=%%a
for /f "tokens=1" %%a in ('powershell.exe .\BOX.ps1') do set boxid=%%a
echo %tagid%
echo %phaseid%
echo %boxid%
timeout /t 3 /nobreak
Set Backup=%HOMEDRIVE%\Backup\%tagid%\%PhaseID%\%BoxID%
等..........
[/ CODE]
输出如下:
C:\Users\Administrator>for /F "tokens=1" %a in ('powershell.exe .\TAG.ps1') do set tag=%a
C:\Users\Administrator>set tag=AH0417
C:\Users\Administrator>for /F "tokens=1" %a in ('powershell.exe .\PHASE.ps1') do set phase=%a
C:\Users\Administrator>set phase=WJFKB02229001
C:\Users\Administrator>for /F "tokens=1" %a in ('powershell.exe .\BOX.ps1') do set box=%a
C:\Users\Administrator>set box=A
C:\Users\Administrator>echo AH0417
AH0417
C:\Users\Administrator>echo WJFKB02229001
WJFKB02229001
C:\Users\Administrator>echo A
A
C:\Users\Administrator>pause