Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scons - running program after compilation

Tags:

c++

python

scons

I want to run the built program directly after compilation, so that i can build and start my program with scons.

I thought that this SConstruct-File, would start the program, whenever it is rebuilt.

main = Program( "main", [ "main.cc" ] )

test = Command( None, None, "./main >testoutput" )
Depends( test, main )

And this would start it, every time I run scons

main = Program( "main", [ "main.cc" ] )

test = Command( None, None, "./main >testoutput" )
Requires( test, main )

But both don't work, my program is never executed. What am I doing wrong?

like image 659
dinfuehr Avatar asked Jun 17 '12 09:06

dinfuehr


1 Answers

This should work better to run the program only when its built.

main = Program( "main", [ "main.cc" ] )

test = Command( target = "testoutput",
                source = "./main",
                action = "./main > $TARGET" )
Depends( test, main )

And use the AlwaysBuild() to run it every time, as mentioned by @doublep like this:

main = Program( "main", [ "main.cc" ] )

test = Command( target = "testoutput",
                source = "./main",
                action = "./main > $TARGET" )
AlwaysBuild( test )

And if you want to see the contents of the testoutput, you could do this:

(Assuming Linux. It would be more portable to print the file with some Python code instead)

main = Program( "main", [ "main.cc" ] )

test = Command( target = "testoutput",
                source = "./main",
                action = ["./main > $TARGET",
                          "cat $TARGET"] )
AlwaysBuild( test )
like image 139
Brady Avatar answered Sep 17 '22 23:09

Brady