How can I tell which command / operation Origen is currently running? - origen-sdk

In my application code I have logic which could be hit in either a program or a pattern generation run and I need to handle them differently.
How can I tell whether Origen is currently generating a pattern or a program, or any other command?

Origen.current_command will return the name of the currently executing command.
This will return the full name of the command in string format, i.e. if you run origen g my_pattern then it will return "generate".
The full names of the most commonly used Origen commands are:
generate
program
interactive
compile

Related

How to call external "interactive/TUI" command, interact, and read std output

I am trying to write my first vim script, so I apologize if this question boils down to not understanding the basics.
The main goal is that I want to call out to an external command from inside vim and read the results back into the file.
I know how to do this with simple shell commands, e.g. r !ls. However the command I want to interact with is "interactive".
I don't know if this is a meaningful description. But calling this command in the shell opens a TUI, then after interacting with the TUI the command will exit and put things into standard output. I want to read that standard output back into vim.
Possibly it will help to discuss the specific command, which is papis a cli citation manager. If you call, e.g. papis list --format '{doc[title]} {doc[author]}' in the shell it will open up a TUI that allows me to filter down and select a document. After selecting the document it will put the title and author into the standard output. This is what I want to read into vim.
However, my first few attempts have not been successful. Trying the naive :r !papis list results in an error, even though that command is valid in the shell and would result in the TUI being opened. So I'm obviously missing something.
Can anyone recommend a guide or suggest a possible solution for correctly calling out to TUI-based external commands and reading back their standard output?

Custom Build System not displayed when set to Automatic

I wrote a custom build system to compile and run a cpp file, as below:
{
"cmd": [
"clang++",
"-o",
"$file_base_name.out",
"$file",
"&&",
"./$file_base_name.out"
],
"selector": "source.cpp",
"quiet": true
}
It is not being shown in the automatic build systems, which I assume is due to the selector not being recognized. What do I need to change?
Indeed the scope selector that you're using is not correct here; the scope of C++ files is source.c++ and not source.cpp. You can use Tools > Developer > Show Scope Name from the menu (or the associated key) while you're editing a file to see the full scope at the current cursor location. For a build system the first line in the scope popup is the one you want to use.
There's another issue with your build (which you have alluded to in the comments) that the build doesn't work as expected. The reason for that is that you're using cmd to execute your build, but you're use shell constructs (the &&).
When you specify cmd in a build system, you provide a list of strings; the first item is the name of the program that you want to execute (here it's clang++), and the remaining items are arguments to be given to the program being executed.
So in this case, you're asking Sublime to execute clang++ directly, and one of the arguments that you're providing to it is &&, which it assumes is the name of a file. The intention is to try and run the program if it successfully compiles, but using && is a function of your shell (e.g. bash or the like) and not of clang.
You can try adding "shell": true to your build, which tells Sublime that it should try to execute cmd through the system shell instead; that passes everything as a whole to the shell, which does know how to handle &&.
The other alternative is to use shell_cmd instead; in that case you provide a single string that represents the command line that you would enter into the terminal. In this case when you execute the build, Sublime automatically passes the value to the shell for execution.
In your case, that might look like:
"shell_cmd": "clang++ -o \"${file_base_name}.out\" \"$file\" && \"./${file_base_name}.out\"",
Apart from the value being a single string, it's also important to note that if your filenames can potentially contain spaces, you need to wrap all filename arguments in double quotes so that the shell handles things properly.

Python Terminal Calls Fail to Interact with Files

I am writing a program that handles some data on a server. Throughout the program, many files are made and sent as input into other programs. To do this, I usually make the command string, then run it like so:
cmd = "prog input_file1 input_file2 > outputfile"
os.system(cmd)
When I run the command, however, the programs being called report that they cannot open the files. If I run the python code on my local computer, it is fine. When I loaded it onto the server, it started to fail. I think this is related to issues with permissions, but am not sure how I can fix this. Many of the files, particularly the output files, are being created at run time. The input files have full permissions for all users. Any help or advice would be appreciated!
Cheers!
The python code you list is simple and correct, so the problem is likely not in the two lines of your example. Here are some related areas for you to check out.
Permissions
The user running the python script must have the appropriate permission (read, write, execute). I see from comments that you've already checked this.
What command are you running
If the command is literally typed into your source code like in the example, then you know what command is being run, but if you are generating any part of it (eg. the list of operands, the name of the output file, other parameters, etc), make sure there are no bugs in the portions of your code that generate the command. For example before the call to os.system(cmd) consider including a line like print("About to execute: " + cmd) so you can see exactly what will be run.
Directly invoke the command
If all the above looks good, try to execute the command directly at a terminal on your server. What output do you get then. It's possible that the problem is with the underlying command itself rather than your python code.

starting program in new terminal window

I have a program that needs to start another program. On my mac I did this using system("open path"), but on linux that doesn't work. and using system(./path) is not what I want since than it overtakes the running program.
So is there any way to get the same behaviour as the mac 'open path' command on linux?
(linux noob btw:p)
If you're running the application in a GUI environment, this should be possible but the approach is different. You need to start a new terminal instance explicitly.
Determine the path to your terminal application. This depends on the linux distribution.
Next, check the documentation of that particular terminal application and find out how it can be started to run an application (your application) instead of a shell. This probably involves using some application-specific command line options. Test that in a terminal window, until you have a command line that gives you the desired result. Things could get a little tricky if your application needs command line arguments as well. Use the -- option where necessary.
Then, all you need to do is run that command line from your "parent" application. I would advise however to not use system(). The exec... family functions (using fork and wait) provide better control.

how to perform automated Unix input?

How can you set a string to be used instead of standard input? For example, when running the latex command in Unix it will always find some trivial errors, to skip through all errors you have to enter "r" into the command line (I now know that with latex specifically you can use -interactionmode nonstopmode, but is there a more general solution to do this?)
Is there anyway to specify that this should be done automatically? I tried redirecting standard input to read from a file containing "r\n", but this didn't work.
How can I achieve this?
Not all applications that need input can be satisfied with their stdin redirected.
This is because the app can call the isatty C function (if written in C, or some equivalent call for other languages) to determine if the input come from a tty or not.
In such situation, there is a valuable tool to use, and this is expect.
latex --interaction=MODE
where MODE is one of:
errorstopmode: stop at every error and ask for input
scrollmode: scroll over non-fatal errors, but stop at fatal errors (such as "file not found")
nonstopmode: scroll over non-fatal errors, abort at fatal errors
batchmode: like nonstopmode, but don't show messaes at the terminal
For interactive use, errorstopmode (the default) is fine, for non-interactive use, nonstopmode and batchmode are better.
But beware, there are no trivial errors: all errors must be fixed, and all warnings should be fixed if possible.
Redirecting stdin works without problems here:
/tmp $ tex '\undefined\end' <<< r
This is TeX, Version 3.1415926 (TeX Live 2010)
! Undefined control sequence.
<*> \undefined
\end
? OK, entering \nonstopmode...
(see the transcript file for additional information)
No pages of output.
Transcript written on texput.log.
You've got two plausible answers detailing the way to handle Latex specifically. One comment indicates that you need a more general answer.
Most usually, the tool recommended for the general solution is 'expect'. It arranges for the command to have a pseudo-tty connected for input and output, and the command interacts with the pseudo-tty just as it would your real terminal. You tell 'expect' to send certain strings and expect certain other strings, with conditional code and regular expressions to help you do so.
Expect is built using Tcl/Tk. There are alternative implementations for other languages; Perl has an Expect module, for example.
From the man page:
-interaction mode
Sets the interaction mode. The mode can be either batchmode, nonstopmode, scrollmode, and errorstopmode. The meaning of these modes is the same as that of the corresponding \commands.
Looks like -interaction nonstopmode might help you.

Resources