Start new cmd.exe and NOT inherit environment?

Anders’ recipe has detailed control over a new environment, and I’m leaving that as the accepted answer because of that depth control. However one phrase in that answer led to me the method I’ll actually be using for the particular problem which prompted this enquiry. An “environment that is equal to the initial explorer.exe environment”. … Read more

Run a .bat file in Windows using Python code?

This has already been answered in detail on SO. Check out this thread, It should answer all your questions: Executing a subprocess fails I’ve tried it myself with this code: batchtest.py from subprocess import Popen p = Popen(“batch.bat”, cwd=r”C:\Path\to\batchfolder”) stdout, stderr = p.communicate() batch.bat echo Hello World! pause I’ve got the batchtest.py example from the … Read more

CMD Command to delete files and put them into Recycle Bin?

There is a “recycle.exe” command part of the a collection called cmdutils “Recycle.exe is a safe replacement for the DEL command, that sends files to the recycle bin instead of deleting them. Recycle is also more flexible than DEL; you can specify multiple files at once (or use wildcards)” Available at http://www.maddogsw.com/cmdutils (Tool last updated … Read more

Execute Batch file in Windows Subsystem for Linux

Unfortunately at the moment you cannot do so without either using: cmd.exe /c foo.bat …or the following hack using binfmt: sudo sh -c “echo :WindowsBatch:E::bat::/init: > /proc/sys/fs/binfmt_misc/register” You could then just type: foo.bat The problems with this method are that you’d need to be root, run it each time you opened a bash window, probably … Read more

How do I get the equivalent of dirname() in a batch file?

for %%F in (%filename%) do set dirname=%%~dpF This will set %dirname% to the drive and directory of the file name stored in %filename%. Careful with filenames containing spaces, though. Either they have to be set with surrounding quotes: set filename=”C:\MyDir\MyFile with space.txt” or you have to put the quotes around the argument in the for … Read more

File not found.