case
ADM Blog
23Jun/100

How to run python code in Windows batch (bat) files

Here’s the bit of tricky batch file magic that does it:

1
2
3
@setlocal enabledelayedexpansion && python -x "%~f0" %* & exit /b !ERRORLEVEL!
#start python code here
print "hello world"

The way it works is that the first line of the file does two different things.

1. starts python interpreter passing the name of the file in, and the -x option will tell it to skip the first line (containing .bat file code)
2. When python finishes the script exits.

This nifty trick makes it much nicer for writing admin scripts with python on Windows.

27Feb/090

Access all files on your hard disk from the system tray

Hawkscope is an incredibly useful program that allows you to access your hard disk’s content right from your system tray. Forget about My Computer or the desktop because Hawkscope does not simply show you the hard drives but the entire contents on it through pop open menus. The best part is Hawkscope is available for all the three major platforms – Windows, Linux and Mac and it’s open source.

hs-040-win

The program allows you to add custom locations through the Quick Access tab on the settings window. You can also set to view hidden files or even blacklist certain locations from showing. This application is going to save anybody who works on a computer precious amount of time. I’m totally sold.