How to write CHARACTER variable to file in ESQL? - message

I'm trying to implement simple message flow, which reads text file (SWIFT message) and replaces one field value, then I need to put it back to file.
Flow reads file as blob, then I cast message as CHARACTER and doing replacement. As result I get a CHARACTER variable, which I want write to file.

Cast the variable back to BLOB, make it the message root, then send it into a FileOutput node with default settings. Assuming that you are doing the character replacement with ESQL in a Compute node (with its Compute Mode set to change Message), then the subsequent ESQL would be:
SET OutputRoot.BLOB.BLOB = CAST(yourCharVar AS BLOB);

To write a simple CHARACTER (for example, a XML tag like '< tag >') to a file in ESQL you just have to create a compute node and add something like:
DECLARE youCharacterToWrite CHARACTER '<a simple string>';
SET OutputRoot.BLOB.BLOB = CAST(youCharacterToWrite AS BLOB CCSID InputRoot.Properties.CodedCharSetId);
And connect your compute node from out terminal to in terminal of your FileOutput to write in the file.
If you debug the variable in IIB, it will show some Base64 representation of your CHARACTER variable, but it will be correctly written to the file.

Related

Torch write text to file

I'm trying to write text to file according to this documentation:
https://github.com/torch/torch7/blob/master/doc/serialization.md
With the following code:
require 'torch'
torch.save('temp.txt','text')
A new file named temp.txt is created but when I open it in text editor I see a few null symbols before the text.
Is there an other way to do it?
torch.save does not write only text to the file, but it serializes the given object, so these bytes are probably type of object and length of the string or similar. This is the intended way.
If you want to write a file with text only, use normal Lua API:
fd = io.open('temp.txt', 'w')
fd:write('text')
fd:close()

AS400-CRTCMD Localization. Is it possible to change language at run time?

I am actually converting all DDS files to use MSGID instead of plain text. I can now change the display language of the application just by choosing the right library with the MSGF in French, English, ...
But for the commands, it seems that CRTCMD needs a language file at compile time (with PMTFILE) and uses theses strings to generate the command. I could eventually delete the MSGF but the command will display the texts.
What I want to achieve is using the same *CMD object and be able to change the language when needed at run time.
**Edit: assuming a currently supported release, 6.1 or higher...
I think you want to use *DYNAMIC on the CRTCMD PMTFILE() parameter
*DYNAMIC
When the command is prompted, prompt text messages
will be dynamically retrieved from the message file
specified for this parameter using the message
identifiers stored in the *CMD object when the command
was created. The message identifier specified for the
PROMPT or CHOICE parameter on a CMD, PARM, QUAL, or
ELEM command definition statement must be found in the prompt text
message file when the command is being prompted.
So something like
CRTCMD CMD(MYLIB/MYCMD) PGM(MYLIB/MYPGM) SRCFILE(MYLIB/QCMDSRC)
SRCMBR(MYCMD) PMTFILE(*LIBL/MYMSGF *DYNAMIC)

how to overwrite, or delete the file, used by writefile() calls?

I use the following to save screen output to a file
writefile("file.txt"),
tex(expression),
closefile()
The above sends the output of the tex() to the file automatically. which is all and well and what I want. (side-point: It also sends an annoying NIL line each time to the file, which I had to parse put later).
Now, when running the above code again, the file is appended to, which is not what I want. I want to either overwrite the file each time, or if there is a way to delete the file, so I can call delete on it before.
I looked at help and not able to find a command to delete a file, and I also see no option to tell writefile() to overwrite the file?
Is there an option or way around this? I am on windows 7, Maxima version: 5.36.1
Lisp: SBCL 1.2.7
I guess you are trying to capture the output of tex into a file. If so, here are a couple of other ways to do it:
tex (expr, destination);
where destination is either a file name (which is appended) or a stream, as created by opena or openw and closed by close. By the way, destination could be false, in which case tex returns a string.
with_stdout (destination, tex (expr));
where again destination is either a file name (which is appended or clobbered, as determined by the global flag file_output_append) or a stream.
with_stdout could be useful if you want to mix in some output not generated by tex, e.g., print("% some commentary");.

How to add a string to a pot file with .php?

A lot of my website content is stored in a database for this reason I created a script that goes through the content stored in the database and extracts strings that must be added to my .pot file. (which already contains other strings).
I created a function called "add_string($s)" that should add one string to the .pot file but I'm not sure how to do it.
function add_string($s)
{
// Add string to .pot file?
}
How can this be done?
Thanks
A pot file is just a text file in certain format.
You can use file_put_contents with the FILE_APPEND flag to add text to a file.
With regards to the format of the data argument of the file_put_contents call, you will have
lines referencing files starting with #:, lines referencing instructions to translators starting with #. and then lines starting with msgid with the message id and msgstr the message value. You will want to include the newline \n after each line.
See here for an example of the pot file format.
You will probably want to keep track of your strings in PHP data structure as you write them to file or before you write them to file, to avoid duplicating message values in the template.

Proper code for reading the 1st 10 lines of a file into a Lua table?

I'm just learning Lua and my book (Programming in Lua) has a bit of code in it that "reads the first 10 lines of a file:"
a = {}
for i=1,10 do
a[#a+1] = io.read()
end
This doesn't really make any sense to me; doesn't this read ten nil values? Could someone please explain this?
Short version: It boils down to whether io.input was called earlier in code that isn't listed in your question. If it was called, it'll print the first 10 lines of that file (explained in detail below). If it wasn't called earlier and you're running from the command line or interactively, it'll print the first 10 lines that you type into the console once that code executes. For other cases, it just depends on how the app is launched.
The Lua 5.1 reference manual for io.read says the following:
io.read (ยทยทยท)
Equivalent to io.input():read.
And the documentation for io.input says:
When called with a file name, it opens the named file (in text mode), and sets its handle as the default input file. When called with a file handle, it simply sets this file handle as the default input file. When called without parameters, it returns the current default input file. [...]
And the documentation for file.read (file being the object returned by calling io.input()) says:
Reads the file file, according to the given formats, which specify what to read. For each format, the function returns a string (or a number) with the characters read, or nil if it cannot read data with the specified format. When called without formats, it uses a default format that reads the entire next line [...]
So there are two possibilities here:
io.input was called previously with a parameter (some code not shown in your question), setting the default input file. Calls to io.read with no parameters will return the "default format" of that input file, which is "the entire next line."
io.input was not called previously with a parameter (which is true in your case if there's no additional code). Calls to io.read with no parameters will return "the entire next line" of the standard input, such as the user's command line input if the program is running from the command line.
In the first case, nil will be returned by io.read() after it has finished reading all the lines of the file. This could mean 10 instances of nil get read, but it depends on the file.
In the second case, nil will be returned if the standard input is exhausted, which could happen in different ways, depending on how the app is launched. This too could mean 10 instances of nil.

Resources