2016-09-14 3 views
2

バッチファイルのコードとVBScriptのコードを含むバッチファイルを作成しました。今私はバッチファイルからVBScriptに変数値を渡そうとしていますが、うまくいきません。VBスクリプトファイルにバッチファイルの変数を使用する方法

私は取得しています出力後
echo This is batch 
set /p Name="Enter Your Name: " 
:x=msgbox("You have Entered '" & name & "'" ,0, "Your Title Here") 
findstr "^:" "%~sf0">temp.vbs & cscript //nologo temp.vbs & del temp.vbs 
echo This is batch again 

c:\Users\vshah\Desktop>echo This is batch 
This is batch 

c:\Users\vshah\Desktop>set /p Name="Enter Your Name: " 
Enter Your Name: Vinkesh 

c:\Users\vshah\Desktop>findstr "^:" "c:\Users\vshah\Desktop\Print.bat" 1>temp.vbs & cscript //nologo temp.vbs & del temp.vbs 

c:\Users\vshah\Desktop>echo This is batch again 
This is batch again 

c:\Users\vshah\Desktop> 

In Message Box I am getting message only -- You have Entered " 
Not getting variable output 

は親切に私はVBScriptコードにバッチコードから変数を渡すと

は事前にどうもありがとうございましたそれらを使用するために役立つ...

答えて

1

単純にこの変更:この中

:x=msgbox("You have Entered '" & name & "'" ,0, "Your Title Here") 
findstr "^:" "%~sf0">temp.vbs & cscript //nologo temp.vbs & del temp.vbs 

:あなたは本当に変数をこのように渡して、それのリテラル値が含まれている一時的なスクリプトを作成していない

echo x=msgbox("You have Entered '%name%'" ,0, "Your Title Here")>temp.vbs 
cscript //nologo temp.vbs & del temp.vbs 

注意を変数。 VBScriptで実際に変数を使用する場合は、コードを次のように変更する必要があります。

echo name=WScript.Arguments.Unnamed(0)>temp.vbs 
echo x=msgbox("You have Entered '" ^& name ^& "'" ,0, "Your Title Here")>>temp.vbs 
cscript //nologo temp.vbs "%name%" 
del temp.vbs 
1

正しいmsgboxが生成されます。

@echo off 
setlocal enabledelayedexpansion 
echo This is batch 
set /p Name="Enter Your Name: " 
:x=msgbox("You have Entered '__name__'" ,0, "Your Title Here") 
findstr "^:" "%~sf0"> %TEMP%\str 
set /p vbl=<%TEMP%\str 
del %TEMP%\str >NUL 
set vbl=%vbl:__name__=!name!% 
rem remove the first colon 
echo %vbl:~1% 1>temp.vbs & cscript //nologo temp.vbs & del temp.vbs 

私はenabledelayedexpansionと共にテンプレート(__name__)を使用して、変数内の変数で値を置き換えることができました。 後で削除する別の一時ファイルも作成する必要がありました。

関連する問題