GVKun编程网logo

与goto命令不起作用的Windowsbatch file

13

如果您想了解与goto命令不起作用的Windowsbatchfile的知识,那么本篇文章将是您的不二之选。同时我们将深入剖析batchfile在Windows中运行其他batchfile、batch-

如果您想了解与goto命令不起作用的Windowsbatch file的知识,那么本篇文章将是您的不二之选。同时我们将深入剖析batch file在Windows中运行其他batch file、batch-file – BATCH – 从Windows命令行获取显示分辨率并设置变量、LF与Windowsbatch file中的CRLF行结尾、windows – 为什么输出传输时某些“for”命令不起作用?的各个方面,并给出实际的案例分析,希望能帮助到您!

本文目录一览:

与goto命令不起作用的Windowsbatch file

与goto命令不起作用的Windowsbatch file

GOTO命令和附属标签有问题。

事实:从一个文件夹(他们是日志错误)的一堆文件,我需要打开它们,并检查它们是否包含特定的string。 如果是,则从文件名中删除一些字符(最后出现“_”后的所有字符,包括它自己)并执行其他操作。

为了切断字符我使用GOTO命令循环的方式,因为我发现它在这里描述: http : //www.robvanderwoude.com/battech_while_loops.PHP

脚本是:

命令解释

批量程序来检查过程是否存在

在同一个shell(bash)中运行脚本

我可以用命令行上的Windows行结尾来replaceUnix行尾吗?

如何使“du”命令运行而不输出所有目录,如安静模式?

@echo off setlocal EnableDelayedExpansion cls for %%X in (D:e-puboutBoxlogs*.*) do ( for /F "tokens=7" %%s in (%%X) do ( if /i "%%s"=="<ml>" ( SET fisier=%%~nX SET cond=!fisier:~-1! SET fisier=!fisier:~0,-1! :loopStart rem condition to break the loop if !cond!==_ goto loopEnd SET cond=!fisier:~-1! SET fisier=!fisier:~0,-1! goto loopStart :loopEnd rem here it should be out of a loop rem other stuff to do with var !fisier! rem the following line is not executed because of the label loopEnd echo !fisier! ) ) ) pause

该脚本没有运行,因为标签loopEnd后有一个空行? 如果我在该标签后面写任何指令,它们将被执行,但是第一个for语句的其余迭代不会被执行(日志错误文件夹包含更多的一个文件)

有人可以提供帮助吗?

Unix命令“uniq”&“sort”

sed命令在多行search后插入多行string

如何从Windows上的CMD中的任何位置调用.bat文件

编写rakefile在Windows中运行命令的最佳方法是什么?

如何用空格列出所有文件后面的PHP标签

你有两个问题。

一个问题是goto打破了一个for循环。 另一方面,括号中的标签相当困难。

即使goto的标签位于同一个块中,goto也会始终中断,而且所有嵌套的循环都会被中断,并且跳转后立即丢失for变量。

在括号里面是“两行”的! 我用标签进行了实验,这里有一些括号的结果。

当出现标签时,下一行必须采用正确的“辅助”格式。

这就是为什么失败。

( :this label fails with a Syntax error ) ( :this works :because this line is a "legal" secondary line ) ( :: The remark style :: fails,because it's not "legal" to use a double colon,because it's not a legal path (in the most cases) ) ( :and Now I got courIoUs & echo This will not echo'd :but & echo You can see this ! )

对于第二行,批解析器的一些步骤将被跳过。

@不起作用, @echo.bat @echo Hello试图启动一个名为@echo.bat的文件。

括号的分割失败,就像echo( hello 。

将标签作为文件名称进行处理:echo只有在:echo才会检查:echo是有效的文件名,然后跳过该部分。

::hello在驱动器:: ::hello搜索。

出于测试目的,可以使用subst :: c:temp创建drive :: 。

由于标签在第二行被简单忽略,所以&符号和管道都可以工作,但::上的文件必须存在。

( echo @echo This is %~f0 ) > %TEMP%testLabel.bat REM create Drive :: subst :: %temp% ( :Label ::testLabel.bat The bat will not be executed | echo But this ) subst /D ::

batch file在Windows中运行其他batch file

batch file在Windows中运行其他batch file

我想使用一个batch file来打开多个cmd窗口并在其中运行命令。

这是我现在拥有的:

start cmd.exe /k "grunt watch" start cmd.exe /k "nodemon server.js"

它创build了2个新的cmd窗口,它似乎在运行命令。 但是,cmd窗口中没有显示任何内容。 通常会显示grunt watch和nodemon server.js 。 我怎样才能打开2个窗口,仍然显示消息?

改变目录停止%〜dp0工作

batch file中的redirect和重复操作符是什么?

Windows批处理脚本来解压目录中的文件

复制项目命令在Powershell命令行中工作,但不在bat文件中

直到find该行并用另一个文本文件windows批处理脚本replace

batch file以cpu为单位获取cpu温度并设置为variables

如何检查文件扩展名,并相应地打开Windowsbatch file中的默认程序

脚本.bat可以更改Windows PATH环境variables

我正在尝试为文件列表中的每个文件名添加一个前缀。 我怎样才能确定哪些文件已经添加了前缀?

生成Windows批处理中每个子目录中最新文件的列表

正如Fawzan所说,您可以创建两个不同的批处理文件,以便每个可以打开一个程序。 我已经测试了这个,它似乎功能如何你想它的功能,你必须先运行grunt.bat :

grunt.bat

@echo OFF echo Let''s run Grunt watch grunt watch start cmd.exe /k nodemon.bat pause

nodemon.bat

@echo OFF echo "Let''s run nodemon server.js" nodemon server.js pause

希望这对你有用

总结

以上是小编为你收集整理的batch file在Windows中运行其他batch file全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

batch-file – BATCH – 从Windows命令行获取显示分辨率并设置变量

batch-file – BATCH – 从Windows命令行获取显示分辨率并设置变量

@echo off
set h=wmic desktopmonitor,get screenheight
set w=wmic desktopmonitor,get screenwidth
echo %h%
echo %w%
pause

而不是得到 –

1600
2560

我明白了 –

echo wmic desktopmonitor,获取screenwidth

echo wmic desktopmonitor,获取屏幕高度

我希望这个批处理脚本能够获得我的显示分辨率大小并将其设置为高度和宽度变量,并且能够回显数量.
但它似乎没有起作用.

解决方法

使用desktopmonitor,您只能获得dpi.对于像素分辨率,您需要Win32_VideoController:

@echo off

for /f "delims=" %%# in  ('"wmic path Win32_VideoController  get CurrentHorizontalResolution,CurrentVerticalResolution /format:value"') do (
  set "%%#">nul
)

echo %CurrentHorizontalResolution%
echo %CurrentVerticalResolution%

如果你想我也可以添加一个dpi分辨率吸气剂?
如果有多个显示器,我将不得不修改脚本……

另一种允许你获得更多监视器分辨率的方法是使用DxDiag(虽然它会创建一个临时文件并且会更慢):

随着dxdiag:

@echo off

del ~.txt /q /f >nul 2>nul
start "" /w dxdiag /t ~
setlocal enableDelayedExpansion
set currmon=1 
for /f "tokens=2 delims=:" %%a in ('find "Current Mode:" ~.txt') do (
    echo Monitor !currmon! : %%a
    set /a currmon=currmon+1

)
endlocal
del ~.txt /q /f >nul 2>nul

这将打印所有显示器的分辨率.

编辑:

一个wmic脚本,它将检测Windows的版本,并在需要时使用不同的wmi类:

@echo off

setlocal
for /f "tokens=4,5 delims=. " %%a in ('ver') do set "version=%%a%%b"


if version lss 62 (
    ::set "wmic_query=wmic desktopmonitor get screenheight,screenwidth /format:value"
    for /f "tokens=* delims=" %%@ in ('wmic desktopmonitor get screenwidth /format:value') do (
        for /f "tokens=2 delims==" %%# in ("%%@") do set "x=%%#"
    )
    for /f "tokens=* delims=" %%@ in ('wmic desktopmonitor get screenheight /format:value') do (
        for /f "tokens=2 delims==" %%# in ("%%@") do set "y=%%#"
    )

) else (
    ::wmic path Win32_VideoController get VideoModeDescription,CurrentVerticalResolution,CurrentHorizontalResolution /format:value
    for /f "tokens=* delims=" %%@ in ('wmic path Win32_VideoController get CurrentHorizontalResolution  /format:value') do (
        for /f "tokens=2 delims==" %%# in ("%%@") do set "x=%%#"
    )
    for /f "tokens=* delims=" %%@ in ('wmic path Win32_VideoController get CurrentVerticalResolution /format:value') do (
        for /f "tokens=2 delims==" %%# in ("%%@") do set "y=%%#"
    )

)

echo Resolution %x%x%y%

endlocal

LF与Windowsbatch file中的CRLF行结尾

LF与Windowsbatch file中的CRLF行结尾

我有一个混合的Ubuntu,OS X和Windows git存储库,其中包含可在Windows 7和更高版本上使用的.bat和.cmd文件。 core.autocrlf被设置为input ,所以post- checkout这些文件在我的工作目录中有LF行尾,而不是我开始使用的CRLF行尾。

这会导致Windows批处理执行问题吗? 在什么情况下,这种差异是显着的? 我还没有看到任何问题,但希望防守编码。

使用带有引号的Windows命令行FOR命令

在批处理中显示variables

batch file中的MS-DOS FTP命令:引发错误

BAT文件:奇怪的SET(?)行为

CasperJS exit()退出bat文件?

您可以使用以下.gitattributes文件覆盖批处理文件:

*.bat text eol=crlf

从Unix的行尾写入批处理文件是否安全? 有关于标签无法正确使用LF的评论。 该修复很容易。

windows – 为什么输出传输时某些“for”命令不起作用?

windows – 为什么输出传输时某些“for”命令不起作用?

作为我所看到的问题的一个例子,命令
for /D %%i in (*) do @if not exist m:\home\%%i echo %%i

给我一个当前目录中另一个目录中不存在的目录列表.

但是,如果我想将输出传递给另一个命令,例如:

(for /D %%i in (*) do @if not exist m:\home\%%i echo %%i) | findstr /n .

我收到此错误消息:

echo was unexpected at this time.

请注意,我不能将括号括起来,因为这会导致管道操作符在循环的每次迭代中被处理一次;我需要将循环的输出通过管道传递给应用程序的单个实例.例如,如果我在此示例中省略括号,则findstrc中的行号将始终显示为1,而不是计算目录数.

有人知道如何使这项工作,最好是在一般情况下,而不仅仅是这个具体的例子?

Windows 7 SP1 x64.

这是具有特殊IF语法形式的解析器的问题,如:

IF exist
IF defined
IF errorlevel
IF x EQU y

但是这个没有问题

IF x == y

它可以通过定义包含单个IF的变量来解决.

set "_IF_=IF"
( %%_IF_%% defined path echo It's defined ) | more
( %%_IF_%% errorlevel 0 echo Errorlevel is 0 or above ) | more

这是有效的,因为%% _ IF _ %%将在子进程解析块之前进行扩展.

关于与goto命令不起作用的Windowsbatch file的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于batch file在Windows中运行其他batch file、batch-file – BATCH – 从Windows命令行获取显示分辨率并设置变量、LF与Windowsbatch file中的CRLF行结尾、windows – 为什么输出传输时某些“for”命令不起作用?等相关内容,可以在本站寻找。

本文标签: