batch-file

Batch file to maximize current window

半腔热情 提交于 2021-02-07 07:47:15
问题 I built a batch program that I am currently tweaking to make it more readable/user friendly. I would like my .bat file to automatically be set to maximize in the .bat file itself. I read about START /MAX online, but that just opens a new instance of a command prompt window. I don't want to have two .bat files just to maximize one. I know the windows keys to maximize is ALT + SPACE then X . I got the idea maybe I could use some kind of SendKeys in batch scripting to automate that? I didn't

Exit from nested batch file

左心房为你撑大大i 提交于 2021-02-07 06:26:07
问题 I have 4 batch files, suppose a.bat, b.bat, c.bat and d.bat. Now these batch files are called in such a manner that a.bat calls b.bat, b.bat calls c.call and so on. If I get any error in any batch file, I want to exit from the entire program by saying an error occurred, and mention which batch file had a problem. My question is , how can I do this? Here I used exit /b but it only gets out from the current batch file and moves back into batch file from whence it was called: a.bat @echo. off

How to get position of the sub string in string in batch

二次信任 提交于 2021-02-07 05:59:28
问题 Get The position of the substring, Set str1=This is Test string Set sstr=Test Here i need to get the position of "Test"(8). Thanks... 回答1: @echo OFF SETLOCAL Set "str1=This is Test string" Set "sstr=Test" SET stemp=%str1%&SET pos=0 :loop SET /a pos+=1 echo %stemp%|FINDSTR /b /c:"%sstr%" >NUL IF ERRORLEVEL 1 ( SET stemp=%stemp:~1% IF DEFINED stemp GOTO loop SET pos=0 ) ECHO Pos of "%sstr%" IN "%str1%" = %pos% (This returns "9", counting the first position as "1". The definition is in the mind

Start a process in a new window from a batch file

久未见 提交于 2021-02-07 04:46:05
问题 I have written a batch file (.bat) in windows. I want to execute a particular process in a new window. How do I do this? Example a.py -s 3 -l 5 b.py -k 0 -> I want to start this in a new window and let the original batch file continue C:\program.exe ... .... 回答1: Use the start command: start foo.py or start "" "c:\path with spaces\foo.py" 回答2: start "title" "C:\path\to\file.exe" I would highly recommend inserting a title so that you can call that title later via the TASKKILL command if needed

git grep and xargs in Windows Batch file?

风格不统一 提交于 2021-02-07 04:29:18
问题 I am trying to create a Windows friendly .bat implementation of the following .sh script. The top few lines are all fine, just add SET and cd is fine. git grep is fine, however, xargs isn't... What would the git grep | xargs logic look like in .bat ? INFINITY=10000 TOPDIR=$(pwd) METEOR_DIR="./code" cd "$METEOR_DIR" # Call git grep to find all js files with the appropriate comment tags, # and only then pass it to JSDoc which will parse the JS files. # This is a whole lot faster than calling

git grep and xargs in Windows Batch file?

孤街浪徒 提交于 2021-02-07 04:28:45
问题 I am trying to create a Windows friendly .bat implementation of the following .sh script. The top few lines are all fine, just add SET and cd is fine. git grep is fine, however, xargs isn't... What would the git grep | xargs logic look like in .bat ? INFINITY=10000 TOPDIR=$(pwd) METEOR_DIR="./code" cd "$METEOR_DIR" # Call git grep to find all js files with the appropriate comment tags, # and only then pass it to JSDoc which will parse the JS files. # This is a whole lot faster than calling

Accessing Batch Functions in another batch file

断了今生、忘了曾经 提交于 2021-02-06 10:15:08
问题 Alright, so lets say we have a file called "lib.cmd" it contains @echo off GOTO:EXIT :FUNCTION echo something GOTO:EOF :EXIT exit /b Then we have a file called "init.cmd" it contains @echo off call lib.cmd Is there anyway to access :FUNCTION inside of init.cmd? Like how bash uses "source" too run another bash file into the same process. 回答1: Change your lib.cmd to look like this; @echo off call:%~1 goto exit :function echo something goto:eof :exit exit /b Then the first argument passed to the

Error Handling with Batch File & Sqlcmd

痞子三分冷 提交于 2021-02-06 09:56:50
问题 I have a batch file that runs some SELECT queries using sqlcmd, puts the results into text files, and uploads those files onto an FTP server. That's all working just the way it should, which is how I like things to work. I've been wondering about what I would do in the event of an error, though. Let's say someone changes the data structure of the database I'm hitting and doesn't notify me. If I ran a sqlcmd SELECT statement and dropped the result into a text file, I would just end up with a

DOS batch: SET variable and ECHO it within (…) block

跟風遠走 提交于 2021-02-06 09:14:48
问题 I had a problem with set not working in a batch file; it took a while to distil the problem; at first I thought it was to do with subroutine calls... The script @echo off setlocal set a=aaa echo a = "%a%" ( set b=bbb echo b = "%b%" ) produces the output a = "aaa" b = "" whereas I'd expect a = "aaa" b = "bbb" Why is this please? Is it a bug in DOS? Perhaps there's something about the (...) command grouping syntax that I'm unaware of. Thanks. 回答1: User delayed expansion and ! instead of % @echo

DOS batch: SET variable and ECHO it within (…) block

南笙酒味 提交于 2021-02-06 09:07:31
问题 I had a problem with set not working in a batch file; it took a while to distil the problem; at first I thought it was to do with subroutine calls... The script @echo off setlocal set a=aaa echo a = "%a%" ( set b=bbb echo b = "%b%" ) produces the output a = "aaa" b = "" whereas I'd expect a = "aaa" b = "bbb" Why is this please? Is it a bug in DOS? Perhaps there's something about the (...) command grouping syntax that I'm unaware of. Thanks. 回答1: User delayed expansion and ! instead of % @echo