dinfuehr
dinfuehr

Reputation: 597

scons - running program after compilation

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?

Upvotes: 8

Views: 6420

Answers (2)

Brady
Brady

Reputation: 10357

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 )

Upvotes: 9

user319799
user319799

Reputation:

This runs ls every time SCons is run:

ls = Command ('ls', None, 'ls')
AlwaysBuild ('ls')
Default ('ls')

You never told SCons why and when it should run your command. You should e.g. add it as a dependency to some other target or make it the default target.

If you want to run command really always, i.e. regardless of what target is being built, you should probably run it using standard Python facilities for launching external programs.

Upvotes: 4

Related Questions