I have been running Minizinc models from the command line, and I get final solutions as output.
I know I can make Minizic print intermedite solutions in the IDE. How can I make the same from the command line, so that they are printed as output like in the IDE? Btw, I'm refering to the output Minizinc prints by default, not to the 'output' (the one that acts like print) that you can include in the code of the model.
To output intermediate solutions you can use the -a flag on optimisation problems. So for example minizinc --solver gecode -a model.mzn data.dzn will solve model.mzn with data.dzn on the Gecode solver and output all intermediate solutions.
Note, however, that the -a flag has has a few peculiarities:
-a for satisfiability will output all solutions instead of intermediate solutions. So while scripting you need to be careful.
Not all solvers support the -a flag. Not all solver will have (or output) intermediate solution.
Related
I want to find the names of all PCs in some subnet.
In order to do this, I type in the following command:
nmap x.x.x.0/24.
(Whereby each x stands for one digit.)
An alternative command to achieve the same thing is supposed to be this:
nmap -sL x.x.x.0/24.
The only difference to the first alternative is supposed to relate to the format in which the results are printed to the command line.
However, not only the format differs but also the content. The result of the first command tells me for each computer on the subnet that it's up.
The result of the second command tells me for each computer on the subnet that it's down!!
What is going on here? Why is the first command telling me the opposite of the second one?
Extracted from nmap documentation:
(-sL option). This feature simply enumerates every IP address in the given target netblock(s) and does a reverse-DNS lookup (unless -n was specified) on each.
That's because -sL is only listing and nothing more. And your other command without parameters is performing real scan.
First, some background. I'm trying to use cvs annotate within a Perl script invoked from a ksh command line to find out who's using bad hex constants in their source code and dole out justice appropriately. I'd like to use stdout for this program strictly for my own structured output, so I can pipe it to a file or to other programs. But, every call to cvs annotate results in a diagnostic message being printed to the console. It takes the form of:
Annotations for <filename>
***********
It's mucking up my stdout! I played around with annotate on the command line, and I figured that these diagnostic messages were coming from stderr, because running this command directly in ksh:
cvs annotate <filename> 1>yay.txt 2>boo.txt
correctly puts the desired annotated output into yay.txt and the diagnostics into boo.txt. However, things get weirder when I try to run this from within a perl script using backticks.
$muhstring = `cvs annotate $filename 2>boo.txt`;
The desired annotated output does appear in $muhstring, but the diagnostics still get printed to the command line, and boo.txt is created as an empty file. There's an admittedly old post on perlmonks.org that says this syntax should work as written. So, what's the deal? Is this a CVS quirk, have I misread the post, or have things changed since 1999? Or is it something else?
Edit: So, it is not, in fact, mucking up stdout. I tried this in ksh:
perl findbadhexowners.pl badhex.txt > out.txt
and the diagnostic messages still printed to the console, but out.txt only contains the annotations. This is fine for my purposes, and I can continue with other code.
That said, it seems like Perl and cvs specifically are interacting a little strangely, especially considering that redirection in ksh works fine and redirection in Perl for other commands like cd works fine - for example, in Perl
`cd nonexistentDir 1>stdout.txt 2>stderr.txt`;
gives the expected output in both stdout.txt and stderr.txt. It's only using cvs annotate from within Perl that produces this problem.
I use win7 and matlab2012a. I want to write a shell script to test my matlab scripts with different parameters. I use cygwin for this task. For example, alpha is the parameter and the matlab script is getall.m. The matlab script will read parameters from txt file 'param.txt'.
#!/bin/sh
# List=`seq 0.1 0.01 1`
List=`seq 0.1 0.1 0.2`
for alpha in $List
do
echo -ne "20\n61\n80\n1\n0.3\n${alpha}" > param.txt
matlab -nodesktop -r "getall;quit;" #time consuming
done
My problem is that script "getall.m" is time consuming, so I'd like to exec it one at a time. But I found that matlab command returns immediately. So the upper script will start a lot of matlab instances at the same time. I also tried the matlab command in cmd, but nothing changes. In ubuntu, matlab blocks the shell by default.
My question is how to make the matlab command to block the shell in windows?
There's a matlab -wait command line switch on Windows that will make it block.
http://www.mathworks.com/help/matlab/ref/matlabwindows.html
I don't know the "right" way to do this - but I do have a hack for you:
Make the matlab script create a file called "matlabDone" in the /tmp directory just before quitting; your shell script can go around a loop looking for this file. Once it exists, you know matlab is finished. Delete the file, and go around the loop again. Something like this:
List=`seq 0.1 0.1 0.2`
for alpha in $List
do
echo -ne "20\n61\n80\n1\n0.3\n${alpha}" > param.txt
matlab -nodesktop -r "getall;quit;" #time consuming
while [ ! -e /tmp/matlabDone ]
do
sleep 1
done
rm /tmp/matlabDone
done
Then make the last line of your matlab script create the file /tmp/matlabDone...
As I said - it's a hack...
PS I am not 100% sure what functions are available in cygwin. If you can't use sleep, I saw an interesting post suggesting that ping -n 2 127.0.0.1 > /dev/null (or equivalent ... depending on the version of ping you might need -c 2 -i 1 to get "one second per ping, count two") can be an alternative to sleep().
I've always found the command-line mysql utility to be a bit surprising, because you can do this:
gzcat dumpfile.sql.gz | mysql -u <user> -p <options>
and mysql will prompt you for a password. Now, stdin in mysql is redirected -- one would expect it to read the password from the dumpfile. Instead, it somehow bypasses stdin and goes straight for the terminal. ssh does the same kind of thing.
I suspect this is some sort of /dev/tty or /dev/pty magic, but I'd appreciate a proper explanation for this apparent magic :) (and why these programs can do it on any platform, even Windows).
As you surmise, it is using /dev/tty, which is specified this way:
In each process, [/dev/tty is] a synonym for the controlling terminal associated with the process group of that process, if any. It is useful for programs or shell procedures that wish to be sure of writing messages to or reading data from the terminal no matter how output has been redirected. It can also be used for programs that demand the name of a file for output, when typed output is desired and it is tiresome to find out what terminal is currently in use.
No real "magic" beyond that.
[link]
Is it possible to integrate Cppcheck with Emacs in a more sophisticated way than simply calling the shell command on the current buffer? I would like Emacs to be able to parse Cppcheck's messages and treat them as messages from a compiler (similar to how compile works), such as using C-x ` to visit the targets of Cppcheck's messages.
Here is some example output Cppcheck:
$ cppcheck --enable=all test.cpp
Checking test.cpp...
[test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check if p is null at line 5
[test.cpp:38]: (style) The scope of the variable 'i' can be reduced
[test.cpp:38]: (style) Variable 'i' is assigned a value that is never used
[test.cpp:23]: (error) Possible null pointer dereference: p
[test.cpp:33]: (error) Possible null pointer dereference: p
Checking usage of global functions..
[test.cpp:36]: (style) The function 'f' is never used
[test.cpp:1]: (style) The function 'f1' is never used
[test.cpp:9]: (style) The function 'f2' is never used
[test.cpp:26]: (style) The function 'f3' is never used
Hmmm... I think this is really simple actually. Just use 'compile', as in M-x compile, and type as the compile command:
cppcheck --template='{file}:{line}:{severity}:{message}' --quiet <filename>
Where the filename is the name of the file on which you wish to run cppcheck. That puts the output of cppcheck into a form that the compilation buffer can parse and gives you the full functionality you get with, for instance, a g++ compile.
The --quiet is probably not necessary but since all I care about are the errors that's what I use.
You can use flymake which ships with Emacs.
The basic idea is to write a flymake command that runs cppcheck and then massages the output into a format the flymake can use. If you then enable flymake in your c++ mode buffers, you'll get on the fly error highlighting.
This is an example of flymake working with my Python buffers using pyflakes.
flymake in general expects output in this form
filename:line_number: class: message
Where filename is the name of the file, number is the line number, class is a string like error or warning indicating the type of message and message is a string indicating the actual error. cppcheck output looks close to this. You should probably write a little wrapper to convert the output of cppcheck to this format and then add a hook to turn on flymake for c++ mode.
With C, adding something like gcc -Wall -o nul -S ${CHK_SOURCES} to your Makefile with under a target check-syntax and running flymake-mode does what's necessary. I think it'll be similar for c++ mode.
For the gory details, you should check out http://flymake.sourceforge.net/
Is it possible to integrate Cppcheck with Emacs in a more sophisticated way
Yes, it is possible. Use flymake. I'm surprised no one has done this yet for cppcheck.
No problem, you can do it yourself. Add cppcheck as a new flavor of flymake tool. To do that, follow an existing example. It's not too complicated to do, but coming in cold, it's hard to know what to do. (I've never seen a guide document that describes how to integrate new tools into flymake). Following an existing working example solves that.
Here's a 7k file that adds PHP CodeSniffer as a flymake tool. http://www.emacswiki.org/emacs/flyphpcs.el
Most of that 7k is comments...
You should be able to modify that to add any arbitrary tool to flymake. The key steps are:
Associate your target file extension (example: .cpp) with a pair of functions (init and cleanup) that do your flymake stuff.
define a function to generate the command line, each time flymake scans your buffer. Ths fn gets the name of the file backing the buffer, and produces a command line. In your case it would run cppcheck with all the appropriate command line parameters. The fn that generates the command line is called by the init fn referenced in #1.
define a regex that matches error messages generated by your tool, and add that regex to the flymake list. This allows flymake to extract error messages from the output of the tool you run. By parsing the output, flymake can get the line numbers and highlight broken lines in your buffer.
based on the answers, flymake sounds good.
you can write a cppcheck parser but it sounds easier to use cppcheck --template option.
cppcheck --template="{file}:{line}:{severity}:{message}" foo.cpp
might match flymake pattern. It is just an idea.
The quickest way is probably to use flymake and add an extra target to your makefile.
This setup is working for me:
check-syntax: cppcheck
g++ -o nul -S ${CHK_SOURCES} $(CFLAGS)
cppcheck:
cppcheck --enable=all --quiet --template={file}:{line}:{severity}:{message} ${CHK_SOURCES}