Calling Python scripts as Visual Studio custom build step.

Bengt Richter bokr at oz.net
Fri Jan 25 16:02:53 EST 2002


On 24 Jan 2002 06:59:02 GMT, bokr at oz.net (Bengt Richter) wrote:
[...]
>Anyway, it can be made to work. Here's a little test hello world program that includes
>a time stamp definition in header file that's regenerated by python script if it's older
>than the .c source:
I see I left some potentially confusing unnecessary cruft in the following. It works,
but sorry about any confusion ;-/
>---- the .c test program ---
>/* testIDE.c */
>
>#include "timestampheader.h"
>#include <stdio.h>
>
>int main(int argc, char* argv[])
>{
>	printf("Hello World! on %s\n",BUILDTIMESTAMP);
>	return 0;
>}
>----the time stamp header generator script ----
>#timestampheader.py
>#writes a new timestampheader.h
>import sys, time
        ^^^-- left over from a version using args, not the fixed .h file name
(also, "from time import time" would be cleaner, to avoid "time." below)
>
>f = open('./timestampheader.h','w')
>f.write('/* timestampheader.h */\n')
>ts = '#define BUILDTIMESTAMP "%s"\n' % time.ctime(time.time())
>f.write(ts)
>f.close()
>print 'Time stamp definition written was:\n%s' % ts
 ^^^^^...--this line unnecessary, but nice to see in the build log
>---a generated .h file --------
>/* timestampheader.h */
>#define BUILDTIMESTAMP "Wed Jan 23 22:51:05 2002"
>---
>
>Use custom build options on timestampheader.h
>with command (use your paths and names to suit)
>    D:\python21\python .\timestampheader.py $(InputPath)
  (args not used in above version of .py)---^^^^^^^^^^^^^
>and output
>    .\timestampheader.h
>and dependencies
>    .\testIDE.c
>(which might be a long list for a big project).
>The output was:
>--
>Hello World! on Wed Jan 23 22:51:05 2002
>Press any key to continue
(This last line was not part of the program output, it was from the MSVC++ debugger
preventing the console prog window that it created for running the program
from instantly disappearing.)
>--
>
>HTH,
Regards,
Bengt Richter





More information about the Python-list mailing list