Run a command in SCons without dependencies - scons

I want to run a command in SCons which doesn't have any input/output files (actually the input and output are the same file). At the moment I am just manually running it with subprocess.Popen but is there a more SConsy way of doing it?

You can use the Command function to run whatever external command you run via Popen, and you can use the AlwaysBuild function to ensure your command is always run even if the target file exists. Scons doesn't like dependency cycles, so leave the source list empty.
myfile = env.Command('myfile.out', [], 'echo Hello world > $TARGETS')
env.AlwaysBuild(myfile)
The scons wiki also has a recipe for PhonyTargets which makes it easy to set up a lot of simple commands.

Related

Run a batch file using "Batch" command

I am currently working on a project in which the deliverable is a .sh file. When I run the file using ./file.sh it works just fine. But according to the prof. we have to run the file using this statement. Batch file.sh. This does not work, and the errors returned are batch accepts no parameters. Which makes sense after reading the man page.
What is the proper way to use the batch command? Is it even possible to run it the way that the professor wants?
According to your description, the file you are trying to execute shouldn't be executed with Batch but Bash/Shell.
Following Batch file, Batch is not supposed to run programs with the sh extension (sh stands for shell).
You can validate what interpreter the program you are trying to use should be run with with the following ways:
Checking the shebang
Using the file command (i.e. file ./your_program.sh)
After finding the correct interpreter, you can run the program with calling it (i.e. sh ./your_program.sh)

Run a .tcl command from a makefile

I am new to writing a makefile which will be executed on a linux machine.
I have the following tasks to do in a makefile:
1)check if the files in the path/directory are exists and modified recently
2)run a .tcl file
I have written the following piece of code..can you please help me.
PATH =/work/source/
task1:
ifeq (,$(PATH))
#echo "error file does not exist!"
endif
#check for files modified
#run the .tcl command
run evaltest.tcl
reports :#echo "reports tbd"
.PHONY : all
all: task1 reports
Please let me know what changes are required for it to run as expected.
You seem to be planning to do way too much work yourself. Your task #1 is typically what make does. So that only leaves task #2. If a Tcl script has the excutable permission and starts with a valid hashbang, you can just execute it. Otherwise invoke tclsh to run it.
Another problem could be that you redefined the PATH variable. On linux, the PATH variable normally contains a list of directories where executable commands can be found. To point to your sources, better use a different variable name, like SRCPATH or so. By redefining PATH, the tclsh command can not be found, unless it is in /work/source.
So the task1 rule of your Makefile could be reduced to:
task1: sourcefile1 sourcefile2
tclsh evaltest.tcl
# Or ./evaltest.tcl
This will execute evaltest.tcl if either sourcefile1 or sourcefile2 is newer than a file called task1. It is assumed that evaltest.tcl will create the task1 file. If either sourcefile doesn't exist and there is no rule to create it, make will tell you about that.

call a shell script(command line tool) inside another shell script

I am using a tool called Droidbox for experiment.
The tool has a shell script droidbox.sh which I can invoke through terminal.
droidbox.sh takes one argument i.e path of the apk
Usage: ./droidbox.sh APK
I want to call the droidbox.sh through a shell script.
I wrote a shell script like
#!/bin/bash
ARG1="/home/xxx/a.apk"
/home/xxx/DroidBox_4.1.1/droidbox.sh "$ARG1"
I am getting error which says
python: can't open file 'scripts/droidbox.py': [Errno 2] No such file or directory
Can anybody point out what am I doing wrong?
Your error message does not come from your script, but from the called one.
It sounds like the droidbox.sh script is not very smart and requires you to set the current working directory before you can call it.
I would typically use also some more variables, so you better see what belongs together:
#!/bin/sh
set -e
BASEDIR="/home/xxx"
DROIDDIR="$BASEDIR/DrroidBox_4.1.1"
APKFILE="$BASEDIR/a.apk"
cd "$DROIDDIR"
"$DROIDDIR/droidbox.sh" "$APKFILE"
If you dont use set -e you better combine commands which need to succeed together:
cd "$DROIDDIR" && "$DROIDDIR/droidbox.sh" "$APKFILE"
Otherwise the cd might fail when the directory is missing and all following commands execute in the wrong directory.
This error is because you're running the script in a different folder than the folder that houses your "scripts/droidbox.py" file. You can fix this in the following way(s):
Move the "scripts/" folder to the directory that you're running this script out of using "mv /path/to/scripts/ ."
Move your customer script to the folder that contains scripts/droidbox.py and run the script from there

How can I change the binary file link to something else

I have two questions and they are linked. I execute the command like this:
python on the shell and it opens the shell.
Now I want
To which file it is linked. I mean when I run python then what is the path of file it opens like /usr/bin/python or what?
The other questions is I want to change that link to some other location so that when I run python then it opens /usr/bal/bla/python2.7.
The command run when you type python is determined primarily by the setting of your $PATH. The first executable file called python that is found in a directory listed on your $PATH will be the one executed. There is no 'link' per se. The which command will tell you what the shell executes when you type python.
If you want python to open a different program, there are a number of ways to do it. If you have $HOME/bin on your $PATH ahead of /usr/bin, then you can create a symlink:
ln -s /usr/bal/bla/python2.7 $HOME/bin/python
This will now be executed instead of /usr/bin/python. Alternatively, you can create an alias:
alias python=/usr/bal/bla/python2.7
Alternatively again, if /usr/bal/bla contains other useful programs, you could add /usr/bal/bla to your $PATH ahead of /usr/bin.
There are other mechanisms too, but one of these is likely to be the one you use. I'd most probably use the symlink in $HOME/bin.

Strange "sh" behaviour

I am developing an application on Beaglebone board with Angstrom distrubition fo Linux.I faced an interesting problem.
When I execute :
sh /home/root/Desktop/BBTCP/out/vehicleDetect 192.168.10.29
in terminal it says
/home/root/Desktop/BBTCP/out/vehicleDetect: /home/root/Desktop/BBTCP/out/vehicleDetect: cannot execute binary file
But when i execute
cd /home/root/Desktop/BBTCP/
and
sh out/vehicleDetect 192.168.10.29
it starts working??
What is the reason and why I can't run tha application with first configuration?
I think it is about the difference between ./ and sh. What are the differences?
My first guess would be that one of the folders in the path /home/root/Desktop/BBTCP is a link. If vehicleDetect is a script and it invokes itself recursively, then this link might be confusing it.
If that's not the case, try sh -x /home/root/Desktop/BBTCP/out/vehicleDetect and see what that prints.
Lastly, check what's in the folder /home/root/Desktop/BBTCP. There might be an executable sh in there. If your path contains ., a different shell might be executed.
Seems like /home/root/Desktop/BBTCP/out/vehicleDetect is invoking a binary file (an executable) that was built on a different architecture.
The main difference between sh and ./ is that ./ will attempt to execute the file itself as an executable, whereas sh will do that for you. It could be that there is a weird magic number at the start of the file, but you would expect sh to complain about that.
Best guess though it is a #! line at the start of the file which either contains invalid characters or refers to a strange file. Did you, for example, bring this script file from another operating system (like Windows) that has different line endings? I have seen similar effects when text file scripts have not been converted but just copied. Maybe you downloaded it in a strange format?
Check with od -xc /home/root/Desktop/BBTCP/out/vehicleDetect and look at the first line.

Resources