batch-file

Code in Command prompt doesn't work in batch file

女生的网名这么多〃 提交于 2020-02-06 04:55:30
问题 The code below does what I want when I execute it in the command prompt but not when I put it in a .bat file and try to execute it: for /f %a in ('dir /b *.csv') do for /f "tokens=*" %b in (%a) do echo %b,%a >> all.csv What am I missing. Also is there a way to have it do exactly what it does without displaying every step in the loop in the command prompt window. Excuse me I am a newbie! 回答1: In batch files - as opposed to at the command prompt - for variables require two %% signs, e.g. %%a .

batch script to rename a file with string (with space) from variable

痴心易碎 提交于 2020-02-06 02:45:30
问题 There is a file named doctitle.txt which contains the title. I want to use this title to rename another file, currently name file.pdf, so I did: for /f "delims=" %%x in (doctitle.txt) do set "DOCTITLE=%%x" move file.pdf %DOCTITLE%.pdf This works fine, if there no space in the title string, i.e "DocumentTitle". But fails if there is a space in the title, i.e "Document Title". What could be done to overcome this issue? 回答1: Try: for /f "tokens=*" %%x in (doctitle.txt) do set DOCTITLE=%%~x move

Is it possible to embed a Ruby code into batch-file?

时光总嘲笑我的痴心妄想 提交于 2020-02-05 23:32:34
问题 Usually this is useful for “self-calling” scripts like in this notorious example The good script with embedded code should not use ugly escape sequences , no temp files and redundant output. Is it possible to be done with Ruby? 回答1: Yes with some hacks.Here’s an example ( file should be with .bat extension ): @break #^ =begin @echo off echo BATCH: Hello world! ruby "%~f0" %* exit /b 0 =end puts 'RUBY: Hello world!' Output will be: BATCH: Hello world! RUBY: Hello world! Here’s the explanation.

How to merge two text files using batch script?

点点圈 提交于 2020-02-05 08:12:45
问题 I have two text files as A.txt and B.txt with the below contents: A.txt value_a1,value_a2 value_b value_c value_d value_e1,value_e2 B.txt 12,14 13 15 16 23,34 I want output file C.txt as "value_a1","12","value_a2","14" "value_b","13" "value_c","15" "value_d,"16" "value_e1,"23","value_e2","34" Please guide me through as I am new to Batch Script. 回答1: Following code will work: @Echo off echo. >>d.txt type b.txt >>d.txt set dec=1 For /F "usebackq tokens=1,* delims=, " %%a in ("a.txt") do call

How can I create a batch that searches all (unknown) shared folders on the local network for a specific folder?

孤人 提交于 2020-02-05 06:45:53
问题 We have several hundred clients with unique server names on their own local networks that hosts a specific folder called "Installs". Ultimately what I'm trying to put together is a batch that finds this folder with said name and use an MSI file in that folder to install on their machine. The server name could just be anything, the only thing I know for sure is that it will be sharing out that specific folder. I've tried many variations of net view, find, dir, wmic share.. no such luck, no

Escaping outputs in CMD

大兔子大兔子 提交于 2020-02-05 06:29:13
问题 If I run something that returns with a & or some other character that has special meaning, and I try to use it in a script, how would I escape it? An example would be if I shared a local account with someone in the same computer, and I had a username that says John & Matt. Putting a batch file in the Desktop directory that had something like this: @ECHO OFF echo %~dp0 It would return something like this: C:\Users\John The system cannot find the path specified. And the whole script from that

goto unexpected with blank choice

青春壹個敷衍的年華 提交于 2020-02-05 05:17:07
问题 My problem: I set a VAR with prompt and three IF to let choice. Fourth choice doesn't work. I would like that if i push enter without type anything, it goes back to :MOSTRA. Actually leaving it blank and typing enter on the keyboard it give back GOTO WAS UNEXPECTED and close CMD. Where am i wrong? :MOSTRA ECHO Make your choice. ECHO. ECHO A) Ok ECHO B) Ko ECHO Esci SET /P choose=Scelta: if /I %choose%==A GOTO OK if /I %choose%==B GOTO KO if /I %choose%==esci GOTO FINE if /I %choose%=="" GOTO

Get Explorer's children in batch

倖福魔咒の 提交于 2020-02-04 21:07:51
问题 I created folder shortcuts for my taskbar and I would like them to stop launching a new explorer every time So I decided to create a batch script, howover I can not get the kids from explorer.exe @echo off pushd tasklist /nh /fi "imagename eq explorer.exe C:\Users\danil\Desktop\ISO" | find /i "explorer.exe C:\Users\danil\Desktop\ISO" > nul ||(start explorer.exe C:\Users\danil\Desktop\ISO) 回答1: The issue with your attempt is that tasklist will list only one instance of explorer.exe but not the

Hadoop 2.3.0 over windows 2008 r2 x64 about nodemanager

馋奶兔 提交于 2020-02-04 05:01:50
问题 everybody, Recently I used Cygwin64, Maven, JDK1.7x64 and hadoop 2.3.0 Src to build package on Windows 2008 r2 x64,and it build success. Finally I set all parameters of hdfs-site.xml,yarn-site.xml,core-site.xml and mapred-site.xml. I go forward to format namenode and excute start-dfs.cmd,the namenode and datanode all work fine. But when I excute start-yarn.cmd to start resourcemanager and nodemanager,only the resourcemanager works fine. The nodemanager cmd window shows "The System cannot find

Node.js as service, exec doesn't work

我只是一个虾纸丫 提交于 2020-02-03 10:54:05
问题 I'm running Node.js project as service using nssm. When user clicks button on my nodejs website it should run require('child_process').exec('cmd /c batfile.bat', function({ res.send(somedata); }); but instead it just skips running bat file and jumps to res.send(somedata) . Why is that? When I run Node.js using cmd and npm start server.js it works fine. How can I make exec work while running nodejs as service? Edit, some code: require('child_process').exec('cmd /c batfile.bat', function(){ var