At work I use a bunch of different programs that are located in many different folders that I have to open when I get here. So I've created a batch file that opens all of them for me.
I've run into an issue with one program that's located on a shared network. In my batch file I put
START "" "\\server\path\program.exe"
It loads the program but when I try to navigate the program is doesn't work. I run into an exception error that says it can't find a file on the C drive. But when I load the same program from the folder without the batch file, it works just fine. Any idea what's causing this?
Try specifying the working folder:
START "" /D "\\server\path" "\\server\path\program.exe"
It's documented in the output of start /?.
Related
I'm trying to get a bat file together and not sure how to run multiple cmd lines through the .bat.
Objective: I want to be able to click on this .bat file to open cmd prompt, then to find a "folder" in the directory, rename the "Folder" then move the location of the folder then find a existing Folder and put it in the same directory.
Problem: i know how to run these cmds in the prompt without an issues.
So far this is what i have:
#echo off
start cmd.exe /k cd %AppData%\Microsoft\Network\Connections
#echo off
and then just write your commands its that simple
A .bat file is executed in a terminal window automatically, you don't need to call cmd.exe or anything like that.
Every single line you write in the .bat file is going to be executed one by one, so you just need to write multiple lines with all the instructions and then you can double click on your new file to run the script.
If you are not familiar with Windows commands for the terminal, you can find more info on the web about how to find a folder, rename it, etc. There are many things you can do by command line and this is not the right place to explain how to use them.
I have created a windows batch file to run a code which is located in a particular folder. However, I am running the batch file but it does not work. What I want it to do is:
Change working directory in Spyder (Spyder is already openned so I don't want it to open it first)
Run the script I want to execute
Basically, the script I am running is plotting a bunch of graphs and all the files needed to create this are located in the working directory.
#echo off
"C:\Users\Mason\Desktop\WinPython-64bit-2.7.6.4\spyder.exe"
chdir /D "F:\optimisation"
"F:\optimisation\plot.py"
pause
The batch file runs fine without any errors, but nothing happens in Spyder e.g. it doesn't change the working directory and neither executes the code.
I'd suggest
#echo off
setlocal
chdir /D "F:\optimisation"
"C:\Users\Mason\Desktop\WinPython-64bit-2.7.6.4\spyder.exe" "F:\optimisation\plot.py"
pause
That is, switch to the required directory, having set a local environment (this restores the original environment when the batch terminates).
Then run the spyder executable, providing it with the name of the file. It would be normal practice to use this structure to provide a significant filename to an executable (eg notepad fred,txt)
Since the current directory when spyder runs is f:\optimisation, it is probably not necessary to specify the entire path in spyder's argument.
Note this is all just speculation using normal practice. I have no experience of spyder- in fact, this is the first I've heard of it.
I'm attempting to write a batch file that will move to the specified directory and then run the command to open my desired program. Specifically I want it to run the command HardwareSimulator so it will open the software nand2tetris provides.
I've gotten it to move to the directory I want, but the opening is my issue. Code is displayed below. I'm guessing start isn't the correct command since when I run, it just runs an infinite loop of opening cmd prompts.
My second question would be: can I only go into sub-directories of where my batch file is already stored? It would be easier to store it in my desktop, so I can just click it whenever, but I can't seem to make it back out of a directory and then go down into another.
start cmd
pushd \nand2tetris\projects\P1Codes
start HardwareSimulator
pause
You can use ..\ to go back a directory.
For instance, if you had nand2tetris in your downloads folder you could get to it from the desktop with this script. Also make sure to to include the file extension.
pushd ..\Downloads\nand2tetris\projects\P1Codes
start HardwareSimulator.exe
pause
I have a batch file that copies files from and to an external hard drive. I wanted to add a section at the end of the script that would automatically eject the hard drive so it could be safely removed. I did some research and found that Remove Drive is my best option. I have it set up to use and working. I can write a bat file
#echo off
RemoveDrive :E -L
and it works perfectly!
However, I've hit a snag. When I add this exact line (well without the #echo off) to the end of my bat file, it fails to eject. My guess is that its the same problem as when you've got files open from a usb drive and try to eject it. It won't work because the system is using it. I tested this by creating a seperate bat file that ran just the RemoveDrive named it "RemoveDrive.bat". I then added to the end of my batch file:
pause
call "RemoveDrive.bat"
When the script hit the pause command. I tried to run the batch file by simply clicking the icon. The eject attempt failed. I pressed any key to continue and the called bat file failed and the script (and cmd window) closed. I then double clicked the icon for "RemoveDrive.bat" and it worked.
So after that long explanation, I was wondering if anyone had any suggestions for how to work around this. I was thinking if there was a way I could use the call function with some sort of delay and could close the cmd window. If I could get the cmd window to close and then have the bat file run automatically, I'm betting that would work.
I have created a bat file to start a Ruby service
working code is:
ruby C:\folder\Projects\folder\folder\script\server
It works fine when I open a command prompt ,paste it and run.
but not working when I created a bat file of it.
bat content is
ruby C:\folder\Projects\folder\folder\script\server
pause
when I run that bat file, it not working as expected. It runs multiple as shown below.
Please help me to resolve it.
The Batch file must have a name different than the process you want to run in it. In this case, the Batch file must not be named ruby.bat, because in this case, the line:
ruby C:\folder\Projects\folder\folder\script\server
placed in the Batch file imply a recursive invocation of itself...