Adding text output to Informix - informix

I have a server running Informix and have 2 questions about text output while code is running.
I have a file that contains the code
sperform rtl_est_dte
isql <g_rtl_mrg1.sql> test
isql <fm_prft.sql> test
isql <whs_prft.sql> test
isql <upgfp_frgt.sql> test
isql <upd_plants.sql> test
Is there a way to add text output between each sql on the output screen so I can tell which step it is on?
OR
Can I add text into the actual SQL coding for each stage that would show in the output when running? Right now all I see is "Selected Database" "Deleted 424 rows" etc. I know how to add hidden text with { … } but not how to display text.

That looks like a shell script. It would be clearer if it started with a shebang and some comments:
#!/bin/sh
#
# Run rtl_est_dte form to get new data,
# then run 5 scripts to process the data, saving the results in file test
Anyway, given that it is probably a shell script, you should be able to add echo lines to annotate what you want:
sperform rtl_est_dte
echo "Running g_rtl_mrg1"
isql <g_rtl_mrg1.sql> test
echo "Running fm_prft"
isql <fm_prft.sql> test
echo "Running whs_prft"
isql <whs_prft.sql> test
echo "Running upgfp_frgt"
isql <upgfp_frgt.sql> test
echo "Running upd_plants"
isql <upd_plants.sql> test
echo "Finished"
I hope you'll be able to give more meaningful names to the steps being run, but that illustrates what you could do.
I also observe that it keeps on zapping the test file, so the information saved by running g_rtl_mrg1.sql is lost when fm_prft.sql is run, and that's lost when whs_prft.sql is run, and so on. Use >> to append to the test file. It would be more conventional to separate the output redirection from the input redirection:
isql <upd_plants.sql >>test
rather than the current:
isql <upd_plants.sql> test
That isn't anything remotely like XML. Still, at least the original author didn't use:
<upd_plant.sql> test isql
That works the same — it confuses everyone who reads it.
You can also embed shell escapes in the .sql files:
SELECT * FROM SomeWhere;
!echo "Hello world!"
SELECT * FROM ElseWhere;
IIRC, the shell escapes don't work if you try to read the .sql file in the isql SQL Editor and then run it. It only works from the command line as in the code in the question.
The progress output (Database selected etc) is written to standard error, for better or worse (worse, IMO, but I wrote my own SQLCMD years before Microsoft produced theirs, precisely because I didn't like what isql did, nor what dbaccess did after it was released).

Related

Getting `spss.Submit` to log commands into the `output` window?

When I execute spss syntax commands from a .sps script, each command is written to the output window before it executes giving me a clear log of exactly how an output was created.
Even if the command is an INSERT command executing a different script - I get a log of the commands from that script.
This is very useful for many reasons:
sanity checking - I can always see exactly what went in to creating a specific output (which filters I used, etc.)
recreation - I (or someone else with this output) can easily re-run the same commands because they're right there.
debugging - if there's an error, I can see which commands caused it
However, when I run commands using spss.Submit inside a python block (in a BEGIN PROGRAM-END PROGRAM block), the actual commands called aren't logged into the output window.
I know I can find a full log in a log file - but that's not helpful.
Is there a way to tell spss to continue to log all the commands in the output window?
You can use set mprint on. before the begin program statement to have the syntax that is run via spss.Submit()show up in the output window. I like simpy putting it on the very top of my syntax file as a "set it and forget it".
For example like so:
set mprint on.
begin program python3.
import spss
vars = list(range(1,11))
for var in vars:
spss.Submit(f'compute v{var} = 0. ')
end program.

Emacs shell or terminal escape characters in compilation buffer for rails tests

I have my emacs set up so that colors in shell buffers work great. I also use the compile command to run individual test files in my ruby on rails environment But when I do that, the ror test functionality puts lots of shell/terminal escape characters into my compilation buffer. Is there any way to get that stuff to display in terminal colors?
BTW: I searched around and tried some things, but they didn't work.
Thanks!
Here's what I have in my .emacs file now. It does not work until the end, but that's OK.
;; This stuff is to ansi-colorize the compilation buffer after a rails test so the terminal colors come through.
(define-derived-mode ansi-compilation-mode compilation-mode "ansi compilation"
"Compilation mode that understands ansi colors."
(require 'ansi-color)
(toggle-read-only 0)
(ansi-color-apply-on-region (point-min) (point-max)))
(defun colorize-compilation (one two)
"ansi colorize the compilation buffer."
(ansi-compilation-mode))
(setq compilation-finish-function 'colorize-compilation)
EDIT
I have switched from using the compile mode to using an async shell command. Here's the code:
(defun run-it ()
"Run it on the current file."
(interactive)
(save-buffer)
(shell-command
(format "my_command %s &"
(shell-quote-argument (buffer-name)))))
(global-set-key "\C-ct" 'run-it)
It saves the buffer first. The & makes it actually interactive so I can enter text in the buffer and the command will get that input. And it colors the command output on the fly, which my compile buffer was not doing.
Backing the comment by Alex Vorobiev, which delivered the answer.
Seems you've put a comint-mode aside and with that the ansi-color-process-output filter.
AFAIU fontifying is done on a per-buffer-base, run from an idle-timer resp. triggered by buffer-changes. If enabled in a output-shell, Emacs might hang, as a lot of changes may occur in short time. Therefor fontification is commonly off here. An alternative approach: M-x MY-MODE at the shell-buffer. Which might need some reset to shell environment or re-start then.

Simple program that reads and writes to a pipe

Although I am quite familiar with Tcl this is a beginner question. I would like to read and write from a pipe. I would like a solution in pure Tcl and not use a library like Expect. I copied an example from the tcl wiki but could not get it running.
My code is:
cd /tmp
catch {
console show
update
}
proc go {} {
puts "executing go"
set pipe [open "|cat" RDWR]
fconfigure $pipe -buffering line -blocking 0
fileevent $pipe readable [list piperead $pipe]
if {![eof $pipe]} {
puts $pipe "hello cat program!"
flush $pipe
set got [gets $pipe]
puts "result: $got"
}
}
go
The output is executing go\n result:, however I would expect that reading a value from the pipe would return the line that I have sent to the cat program.
What is my error?
--
EDIT:
I followed potrzebie's answer and got a small example working. That's enough to get me going. A quick workaround to test my setup was the following code (not a real solution but a quick fix for the moment).
cd /home/stephan/tmp
catch {
console show
update
}
puts "starting pipe"
set pipe [open "|cat" RDWR]
fconfigure $pipe -buffering line -blocking 0
after 10
puts $pipe "hello cat!"
flush $pipe
set got [gets $pipe]
puts "got from pipe: $got"
Writing to the pipe and flushing won't make the OS multitasking immediately leave your program and switch to the cat program. Try putting after 1000 between the puts and the gets command, and you'll see that you'll probably get the string back. cat has then been given some time slices and has had the chance to read it's input and write it's output.
You can't control when cat reads your input and writes it back, so you'll have to either use fileevent and enter the event loop to wait (or periodically call update), or periodically try reading from the stream. Or you can keep it in blocking mode, in which case gets will do the waiting for you. It will block until there's a line to read, but meanwhile no other events will be responded to. A GUI for example, will stop responding.
The example seem to be for Tk and meant to be run by wish, which enters the event loop automatically at the end of the script. Add the piperead procedure and either run the script with wish or add a vwait command to the end of the script and run it with tclsh.
PS: For line-buffered I/O to work for a pipe, both programs involved have to use it (or no buffering). Many programs (grep, sed, etc) use full buffering when they're not connected to a terminal. One way to prevent them to, is with the unbuffer program, which is part of Expect (you don't have to write an Expect script, it's a stand-alone program that just happens to be included with the Expect package).
set pipe [open "|[list unbuffer grep .]" {RDWR}]
I guess you're executing the code from http://wiki.tcl.tk/3846, the page entitled "Pipe vs Expect". You seem to have omitted the definition of the piperead proc, indeed, when I copy-and-pasted the code from your question, I got an error invalid command name "piperead". If you copy-and-paste the definition from the wiki, you should find that the code works. It certainly did for me.

How do I get the Ant <input> task to output åäö (and similar characters) properly?

My first question. Please bear with me!
I have an Ant task that need to get some input from the user before proceeding. I use the Input task to achieve this. The input message will contain Swedish characters (eg å, ä and ö) but I am unable to get Ant to output the message properly. I'm testing this using the command line on a machine running Windows 7 Pro English (but obviously using a Swedish keyboard). Example:
<input message="åäö"/>
will output:
[input] Õõ÷
The build.xml is saved in UTF-8 format. If I do 'chcp' on the command line I get "Active code page: 850".
The same result can be seen when doing an echo:
<echo message="åäö"/>
will output:
[echo] Õõ÷
But in the case of the echo task I'm able to do:
<echo encoding="850" message=åäö">
to get the expected output:
[echo] åäö
The input task does however not have an encoding attribute and I'd very much prefer to not have to define an encoding at all, especially not on a per-task level (since I can't tell for sure on what machine the Ant script will be run from).
PS I have additional problems with the received input if it contains åäö and I set the input as a property that is later used in a filter copy task, but I guess that's a whole other question
I can observe the issue on my Polish Windows.
<script language="javascript">
java.lang.System.out.println("default charset: "
+ java.nio.charset.Charset.defaultCharset());
</script>
reports default charset as "windows-1250" while the console operates at "iso-8859-2" (I guess so).
Looks like <input> task uses the default charset thinking it would match the console input. In case it does not, I managed to override the encoding this way:
set ANT_OPTS=-Dfile.encoding=iso-8859-2
ant
In your case I would try to force 850, as it looks like JRE defaults to something else.
This question helped me to find the property name.
It is also important where ant is run from. If I run it from my ide, jedit console plugin, I don't need to override encoding, because I configured it to operate in windows-1250. So it seems to be another workaround, using an IDE.

Getting Statistics to show up in TC

I've setup teamcity with my sln file and got the unit tests to show up with the CppUnit plugin that teamcity has. And I get test results in the TeamCity UI.
Now I'm trying to get trending reports to show up for my unit tests and code coverage.
As of code coverage, we're using vsinstr.exe and vsperfmon.exe which produces an XML file.
I'm not quite sure as of what steps I should be taking to make the trending reports and code coverage(not as important) to show up.
I've already seen this post, but the answer seems to require editing the build script, which I don't think would work for my case since I'm building through MSBuild and the .sln file, and the tests are being ran through that build.
So basically I'm trying to get the Statistics tab to show up, and I'm not sure where to begin.
Just add simple Powershell step into your build configuration. Something like this:
function TeamCity-SetBuildStatistic([string]$key, [string]$value) {
Write-Output "##teamcity[buildStatisticValue key='$key' value='$value']"
}
$outputFile = 'MetricsResults.xml'
$xml = [xml] (Get-Content $outputFile)
$metrics = $xml.CodeMetricsReport.Targets.Target[0].Modules.Module.Metrics
$metrics.Metric
| foreach { TeamCity-SetBuildStatistic "$($_.Name)" $_.Value.Replace(',', '') }
It uses XML output from FxCop Metrics. You have to update the script for your actual schema.

Resources