I have a script which I can run perfectly if I call it manually in the command prompt.
cd \
cd impressio
cd input
for %%f in (.txt)do (
echo "%%~nf"
"C:\Program Files\Splunk\bin\splunk cmd python" "D:impressio\deployment code\add_null.py" "%%~nf.txt" "%%~nf_processed.txt"
)
When I save this script as <filename>.bat and double-click, it always prompts me an error message: "Program Files is not recognized as an internal or external command".
Is it because of the environment variable setting issue? Did anyone come across such thing before, or does my code have a problem?
Not sure why Program Files is mentioned in the error message, but there does seem to be an issue with the line where you are calling your Python script.
In particular, this bit:
"C:\Program Files\Splunk\bin\splunk cmd python"
should likely be this instead:
"C:\Program Files\Splunk\bin\splunk" cmd python
Related
So basically im trying to making a batch script which renames the directory
"C:\Program Files (x86)\Steam\steamapps\common\SteamVR"
to
"C:\Program Files (x86)\Steam\steamapps\common\SteamVRa"
it switches to SteamVR when enabled and SteamVRa when disabled (this is a segment of the full code)
here is what i cant figure out
after the following code is ran
cd /C "C:\Program Files (x86)\Steam\steamapps\common\SteamVRa"
rename "C:\Program Files (x86)\Steam\steamapps\common\SteamVRa" "SteamVR"
timeout 1 >nul
if exist "C:\Program Files (x86)\Steam\steamapps\common\SteamVRa" (
echo Unknown Error
) else (
echo Steam Vr is Enabled, finished
)
if theres any errors not relating to this or ways the code can be better feel free to mention it as well im not very good with batch files
It comes up with the error "The filename, directory name, or volume label syntax is incorrect."
But directly after that it then says "Steam Vr is Enabled, finished"
cd /C "C:\Program Files (x86)\Steam\steamapps\common\SteamVRa"
Is invalid and generating that message.
There is no /c option to cd.
The /d option would switch your current directory to "C:\Program Files (x86)\Steam\steamapps\common\SteamVRa"
If you change /c to /d you will get another error (The process cannot access the file because it is being used by another process.) The "other process is itself.
If you remove the cd altogether, the process works happily.
I'm new in using cmd and batch script. Here is what I was trying to do with a .bat file.
go to a folder
open that folder in file explorer
open that folder in vscode
start Firefox browser
Sequence doesn't matter here. Doing these tasks in any sequence is fine.
Here are the commands that I initially wrote
cd/
E:
cd folder1/folder2/folder3
code .
start .
start firefox
But with these commands the result I got is
Only vscode started with the folder I wanted to open with vscode
File explorer and Firefox was not starting
cmd.exe continued to run. But it seems like it only executed upto code . command
When I closed vscode, cmd.exe would be closed with it too
Then I changed the sequence of the commands as below
cd/
E:
cd folder1/folder2/folder3
start .
start firefox
code .
This time everything worked as expected. I've looked up documentation for start command but didn't find anything(or maybe I didn't understand) about start . command.
Can anyone explain me why the result changed when I changed the sequence of the commands?
As already mentioned in the comments, code is really a batch file, code.cmd.
If your VSCode installer added a location to your %PATH%, take a look there and you should see code.cmd in that \bin directory.
When you run a batch file from another, if you want control to pass back to the initial script upon completion, you need to run it using the call command.
#CD /D "E:\folder1\folder2\folder3" 2>NUL || Exit /B
#Call "%ProgramFiles%\Microsoft VS Code\bin\code.cmd" .
#Start "" "%SystemRoot%\explorer.exe" .
#Start "" "%ProgramFiles%\Mozilla Firefox\firefox.exe"
If you do not want robust code, and wish to assume file extensions and environment settings, the above could be simplified to this:
#CD /D E:\folder1\folder2\folder3
#Call code .
#Start explorer .
#Start firefox
I've recently installed cmder (or simply 'Commander') portable console emulator for windows, and really like the functionalities it comes with. But how can you (if at all) run batches through it like you can with the Windows command line?
The details:
If you write...
cd C:\test\
REM executeSomething.exe
Pause
... to a textfile and save it as a .bat file you can do can do pretty much anything just by double-clicking that file. I've got a work-flow where I launch a web-application through a batch file. Sometimes this applicaton launches automatically in Chrome, and sometimes it does not. In that case, I'll have to copy and paste a URL to Chrome manually. And that's a real pain. With cmder.exe that's much easier, but I'll have to manually navigate to a folder and start the application through Commander it manually without the luxury of a .bat file.
The functionality I'm trying to run automatically with cmder.exe is simply changing a folder and starting an executable file, specifically Jupyter Lab:
cd C:\jupyterlab\
jupyter lab
Pause
I've tried various approaches with:
#echo off
set CMDER_ROOT=C:\Cmder
start %CMDER_ROOT%\vendor\conemu-maximus5\ConEmu.exe /icon "%CMDER_ROOT%\cmder.exe" /title "Homestead VM" /loadcfgfile "%CMDER_ROOT%\config\ConEmu.xml" /cmd cmd /k "%CMDER_ROOT%\vendor\init.bat cd %CD% && %~1"
as described here, but with no success. The example above does launch commander, but also raises a syntax error:
Current directory: C:\batches
Command to be executed: "C:\Windows\system32\cmd.exe" /k
"C:\Cmder\vendor\init.bat cd C:\batches && "
I'm obviously on to somehting here since I'm able to start Commander, but I'm not sure how to edit the remaining code to run the necessary steps. I do realize that the /title "Homestead VM" part just edits the title of the Commander window:
but I have no idea about the rest.
If this just isn't possible, I'm going to have to try to reassociate .bat files in Control Panel > Default Programs > Associate a filetype, but I'm hoping to avoid that.
Thank you for any suggestions!
System info:
Windows 7, 64 bit
Commander v1.3.12
Edit 1: My (failed) attempt trying to follow a suggestion from Gerhard Barnard
I've saved a file named please.cmd to C:\Windows\System32 that contains this:
#echo off
if not defined CMDER_ROOT set "CMDER_ROOT=C:\Cmder"
start %CMDER_ROOT%\vendor\conemu-maximus5\ConEmu.exe /icon "%CMDER_ROOT%\cmder.exe" /title "Homestead VM" /loadcfgfile "%CMDER_ROOT%\config\ConEmu.xml" /cmd cmd /k "%CMDER_ROOT%\vendor\init.bat cd %CD% && %~1"
I've also saved a file named SObatch.bat in C:\batches that contains this:
if not defined myComs set myComs=0 && please %~0
#echo off
ping localhost
echo %userprofile%
pause
Upon double-clicking SObatch.bat a Windows prompt is opened, and the pings are run:
I just narrowed the window to leave out real-world user-names. But the ping functions are being run and the usual responses are returned.
So I guess it still seems that I've broken something.
Create a file called please.cmd and save it to C:\Windows\System32 as administrator. It should then exist as c:\Windows\System32\please.cmd
#echo off
if not defined CMDER_ROOT set "CMDER_ROOT=C:\Cmder"
start %CMDER_ROOT%\vendor\conemu-maximus5\ConEmu.exe /icon "%CMDER_ROOT%\cmder.exe" /title "Homestead VM" /loadcfgfile "%CMDER_ROOT%\config\ConEmu.xml" /cmd cmd /k "%CMDER_ROOT%\vendor\init.bat cd %CD% && %*"
Now when you create a batch files you need to make some changes in the top of each batch file you want. You would need to add the below line to the very top of the script.
"%systemroot%\system32\please.cmd" "%~f0" && goto :eof
You can also from cmd please command to launch it from the cmder shell. Example:
please ping localhost
Here i'm using batch file to take backups & then zip those backups.Backup process successfully.But zipping process failed and it always show to install the 7zip.But i already installed 7ip.
Here goes my code
#ECHO OFF
osql -S .\sqlexpress -E -i "C:\Sql_Backup.sql" -o "E:\test\testbk.sql"
ECHO.
7za a -tzip "E:\test\newfile.zip" "E:\test\newfile.Bak"
ECHO.
del "E:\test\newfile.Bak"
exit
What does "it always show to install 7zip" mean? Are you seeing an actual error message? Is the error message this?
'7za' is not recognized as an internal or external command,
operable program or batch file.
If so, that's because the program is 7z, not 7za. Just change it in your batch file and see if it starts working...
May be system couldn't find where your 7z.exe is, so just tell your system where your compressing program is by giving the correct path like below:
C:\Program Files\7-Zip\7z.exe a -tzip "E:\test\newfile.zip" "E:\test\newfile.Bak"
I want to write a batch file that will do following things in given order:
Open cmd
Run cmd command cd c:\Program files\IIS Express
Run cmd command iisexpress /path:"C:\FormsAdmin.Site" /port:8088 /clr:v2.0
Open Internet Explorer 8 with URL= http://localhost:8088/default.aspx
Note: The cmd window should not be closed after executing the commands.
I tried start cmd.exe /k "cd\ & cd ProgramFiles\IIS Express", but it is not solving my purpose.
So, make an actual batch file: open up notepad, type the commands you want to run, and save as a .bat file. Then double click the .bat file to run it.
Try something like this for a start:
c:\
cd c:\Program files\IIS Express
start iisexpress /path:"C:\FormsAdmin.Site" /port:8088 /clr:v2.0
start http://localhost:8088/default.aspx
pause
I think the correct syntax is:
cmd /k "cd c:\<folder name>"
This fixes some issues with Blorgbeard's answer (but is untested):
#echo off
cd /d "c:\Program files\IIS Express"
start "" iisexpress /path:"C:\FormsAdmin.Site" /port:8088 /clr:v2.0
timeout 10
start http://localhost:8088/default.aspx
pause
cmd /c "command" syntax works well. Also, if you want to include an executable that contains a space in the path, you will need two sets of quotes.
cmd /c ""path to executable""
and if your executable needs a file input with a space in the path a another set
cmd /c ""path to executable" -f "path to file""
#echo off
title Command Executer
color 1b
echo Command Executer by: YourNameHere
echo #################################
: execute
echo Please Type A Command Here:
set /p cmd=Command:
%cmd%
goto execute
start cmd /k "your cmd command1"
start cmd /k "your cmd command2"
It works in Windows server2012 while I use these command in one batch file.
cmd /k cd c:\
is the right answer
I was trying to run a couple of batch files parallely at startup, if a condition was true.
For this I made a parent batch file which should have checked for the condition and invoke the other child batch files if the condition was true.
I tried to achieve it via START but it gave me an empty black command prompt running in the directory of children batch files, instead of running the children batch files themselves
The thing which worked for me was by using a combination of START and CALL
As an example
condition ...
start call "C:\Users\Amd\conn\wsl_setup - conn1.bat"
start call "C:\Users\Amd\conn\wsl_setup - conn2.bat"
start call "C:\Users\Amd\conn\wsl_setup - conn3.bat"
I know DOS and cmd prompt DOES NOT LIKE spaces in folder names. Your code starts with
cd c:\Program files\IIS Express
and it's trying to go to c:\Program in stead of C:\"Program Files"
Change the folder name and *.exe name. Hope this helps