Batch file 在for语句中使用cscript

Batch file 在for语句中使用cscript,batch-file,vbscript,Batch File,Vbscript,已应答并已修复 我有密码: Dim stringa, stringb stringa = WScript.Arguments.Item(0) stringb = Split(stringa, ".") WScript.Echo "." & Replace(stringb(UBound(stringb)),"`"," ") set pth=%~dp0 set /p patha="File path? " for /F %%G in ('cscript.exe "%pth%GETEXT.v

已应答并已修复
我有密码:

Dim stringa, stringb
stringa = WScript.Arguments.Item(0)
stringb = Split(stringa, ".")
WScript.Echo "." & Replace(stringb(UBound(stringb)),"`"," ")
set pth=%~dp0
set /p patha="File path? "
for /F %%G in ('cscript.exe "%pth%GETEXT.vbs" "%patha%"') do set ext=%%G
在vbs文件中,结合代码:

Dim stringa, stringb
stringa = WScript.Arguments.Item(0)
stringb = Split(stringa, ".")
WScript.Echo "." & Replace(stringb(UBound(stringb)),"`"," ")
set pth=%~dp0
set /p patha="File path? "
for /F %%G in ('cscript.exe "%pth%GETEXT.vbs" "%patha%"') do set ext=%%G
但每当我运行它时,批处理文件在到达for语句时就会关闭。当我将
patha
设置为
C:\Users\Username\somefile.txt
时,它工作正常,但当我使用
C:\Users\Username\Desktop\folder\f older\somefile.txt
时崩溃,有人知道崩溃的修复方法或原因吗

编辑:

通过添加
//nologo
'cscript.exe//nologo”%pth%GETEXT.vbs”“%patha%”修复了此问题。

在自己测试后,它是cscript选项`//nologo所需,否则您将获得标题的前两行,如下面的屏幕截图所示:

'cscript.exe //nologo "%pth%GETEXT.vbs" "%patha%"'

可能您需要使用
'cscript.exe”“%pth%GETEXT.vbs”“%patha%”“”
似乎不起作用。
%pth%
是否将“\”作为最后一个字符?请尝试
%pth%\GETEXT.vbs“
。还有错误消息是什么?是的,
%pth%
返回'C:\Users\Username`。请使用
'cscript.exe//nologo”%pth%GETEXT.vbs”“%patha%”