Get File (txt or csv) in Robot Framework - keyword

I created a text file that has 1 value in it by using Create File keyword
${getDateLetter} = getValue name=date
createFile Resources\\Client\\DateLetter.txt ${getDateLetter}
In other script, I'm trying to read the value in text file using Get File keyword
Library OperatingSystem
${dateLetter} = getFile Resources\\Client\\DateLetter.txt
But it will throw this error
Cell in table 'css=#tbl-letter' in row #2 and column #2 should have contained text 'getFile Resources\Client\DateLetter.txt'.

*** Settings ***
Library OperatingSystem
*** Test Cases ***
Test 1
Keyword 1
Keyword 2
*** Keywords ***
Keyword 1
Create File C:/temp/robot_test/test1.txt Hello World...!!! encoding=UTF-8
Keyword 2
${Test} Get File C:/temp/robot_test/test1.txt encoding=UTF-8 encoding_errors=strict
This works for me, Can you specify what data you are writing into file.

Related

How to open file for writing?

I'm trying to open and write to a file using Dart's IO library.
I have this code:
File file = File("text.txt");
RandomAccessFile raf = file.openSync();
raf.writeStringSync("A string!");
Now when doing this I get the following error in the console:
(OS Error: Access is denied., errno = 5)
So file is not opened for writing, and I'm looking here: open method, and can't figure out how to use open or openSync to get RandomAccessFile I can write to.
It says I need to use write constant to do that but just can't figure out how?
If I try to create FileMode and add it to open method as an argument I get an error saying:
Error: Too many positional arguments: 0 allowed, but 1 found.
So open and openSync methods can't take any arguments, how would one use FileMode, and open method to open a file that is ready for writing? So I need to get RandomAccessFile that is in writing mode? And by default its only in read mode? I'm not trying to use writeString or writeStringSync, I know those methods exist, but I'm interested in how is this done using open and openSync methods that return RandomAccessFile!
Update:
You are getting this error:
Error: Too many positional arguments: 0 allowed, but 1 found.
because the openSync method has no positional arguments, but just one named parameter (mode).
So to fix your code you must add it:
RandomAccessFile raf = file.openSync(mode: FileMode.append); //Or whatever mode you'd to apply
Having said that, there are several other ways to write to a file, most of them listed in the docs:
writeString or writeStringSync, I'd suggest these if what you need is just to write once to a file.
openWrite, which returns a Stream that can be written in order to write to the file.
(All of these methods have a FileMode mode named parameter)

Config u-boot for new board error because __LINUX_ARM_ARCH__

I try some set up config to load u-boot for a new board. My configuration is based on U-boot for Beagle Bone Black. I also follow some changes for new board on https://github.com/PacktPublishing/Mastering-Embedded-Linux-Programming-Second-Edition/blob/master/Chapter03/0001-BSP-for-Nova.patch.
I clone a new u-boot and stand at master branch, after I made config file for new board, I ran make. It has 2 issues:
First is about SYS_TEXT_BASE:
scripts/kconfig/conf --syncconfig Kconfig
.config:22:warning: symbol value '' invalid for SYS_TEXT_BASE
*
* Restart config...
*
*
Boot images
*
Enable support for Android Boot Images (ANDROID_BOOT_IMAGE) [Y/n/?] y
Support Flattened Image Tree (FIT) [N/y/?] n
Enable support for the legacy image format (IMAGE_FORMAT_LEGACY)
[Y/n/?] y
Set up board-specific details in device tree before boot
(OF_BOARD_SETUP) [N/y/?] n
Set up system-specific details in device tree before boot
(OF_SYSTEM_SETUP) [N/y/?] n
Update the device-tree stdout alias from U-Boot (OF_STDOUT_VIA_ALIAS)
[N/y/?] n
Extra Options (DEPRECATED) (SYS_EXTRA_OPTIONS) []
Text Base (SYS_TEXT_BASE) [] (NEW)
Then I search for a SYS_TEXT_BASE and entered a random text base: 0xfff10000. But I think it's not for Beagle Bone.
Error LINUX_ARM_ARCH
In file included from ./arch/arm/include/asm/system.h:6:0,
from ./arch/arm/include/asm/cache.h:11,
from include/net.h:15,
from include/common.h:517,
from lib/asm-offsets.c:14:
./arch/arm/include/asm/barriers.h:32:24: error: operator '>=' has no
left operand #if LINUX_ARM_ARCH >= 7
^~
./arch/arm/include/asm/barriers.h:36:26: error: operator '==' has no
left operand #elif LINUX_ARM_ARCH == 6
^~
Kbuild:43: recipe for target 'lib/asm-offsets.s' failed
make[1]: *** [lib/asm-offsets.s] Error 1
Makefile:1575: recipe for target 'prepare0' failed
make: *** [prepare0] Error 2
For the second issue, this was caused by a Kconfig option being renamed on master (CPU_V7 to CPU_V7A). I changed in Kconfig CUP_V7A to CPU_V7, but still has the same issue. Please look into, thanks.
The text base of the Beaglebone Black Board is CONFIG_SYS_TEXT_BASE=0x80100000. It is specified in configs/omap3_beagle_defconfig.
The symbol __LINUX_ARM_ARCH__ is defined in arch/arm/Makefile based on CONFIG_SYS_ARM_ARCH which is defined in .config. So something must be wrong with your .config file.

How to add to a Lua DissectorTable?

I'm writing a Lua dissector for Wireshark for a complex protocol. The protocol has a message header that includes a msgType field. I want to write a subdissector for each message type, with each subdissector stored in a separate source file.
My top-level script is general.lua which dissects the message header and creates the dissector table:
DissectorTable.new("myProtocol.Message")
dofile(DATA_DIR.."cplane.lua")
cplane.lua is a subdissector for message type 'cplane' and includes the code:
my_dissector_table = DissectorTable.get("myProtocol.Message")
my_dissector_table:add(0x02, myProtocol_cplane_proto)
Both scripts are in the same subdirectory of Wireshark's plugins directory.
When I load the plugins I get error:
Lua: Error during loading:
[string "C:\Program Files (x86)\Wireshark\plugins\2.4...."]:9: bad argument
#1 to 'get' (DissectorTable_get: no such dissector_table)
Lua: Error during loading:
[string "C:\Program Files (x86)\Wireshark\plugins\2.4...."]:170: bad
argument #1 to 'dofile' (dofile: file does not exist)
How can I fix this? Is the problem to do with the loading order of the scripts? Is the dofile() call necessary?
It is not necessary to use dofile as all scripts in the plugins directory are loaded. The order of loading is however not fixed (at least, it is not documented to be fixed). Currently Lua plugins are loaded after other dissectors, so trying to lookup dissector tables in the "global scope" will only work for built-in dissectors, such as tcp.port:
local myproto = Proto("myproto", "My Protocol")
function myproto.dissector(tvb, pinfo, tree)
...
end
-- Register with a built-in dissector table
DissectorTable.get("tcp.port"):add(1234, myproto)
For registering with custom dissector tables, this registration has to be deferred. In C dissectors, you would put the registration in proto_reg_handoff_PROTOABBREV (where PROTOABBREV should be substituted accordingly), but in Lua there is no such function.
The closest you can get is the "init" routine (a property of the Proto class, proto.init). These are called when a capture file is opened, before dissecting any packets. Example:
function myproto.init()
DissectorTable.get("your-custom-table"):add(1234, myproto)
end
Lua: Error during loading: [string "C:\Program Files
(x86)\Wireshark\plugins\2.4...."]:9: bad argument
#1 to 'get' (DissectorTable_get: no such dissector_table)
Answer: This error means that Dissector table is not found. Reason could be that the path is not correct, or the sequence of the file execution.
Lua: Error during loading: [string "C:\Program Files
(x86)\Wireshark\plugins\2.4...."]:170: bad argument #1 to 'dofile'
(dofile: file does not exist)
Answer: For me this error is gone by entering the exactly correct path

Erlang with Erlsom and DTD

I am trying to work with 1 GB XML and DTD file with Erlsom.
The problem is that parse_sax throws an exception becuase it cannot work with DTD file.
Basically i don't need this information so my question is how i tell the
sax_parser to just ignore this?
or even to use try and catch and when the error got catches then to skip this place on the file and continue from there.
This the exception:
** exception throw: {error,"Malformed: unknown reference: uuml"}
in function erlsom_sax_latin1:nowFinalyTranslate/3 (src/erlsom_sax_latin1.erl, line 1051)
in call from erlsom_sax_latin1:translateReferenceNonCharacter/4 (src/erlsom_sax_latin1.erl, line 1024)
in call from erlsom_sax_latin1:parseTextNoIgnore/3 (src/erlsom_sax_latin1.erl, line 922)
in call from erlsom_sax_latin1:parseContent/2 (src/erlsom_sax_latin1.erl, line 898)
in call from erlsom_sax_latin1:parse/2 (src/erlsom_sax_latin1.erl, line 172)
in call from mapReduce:run/0 (/home/alon/workspace/mapReduce/src/mapReduce.erl, line 26)(mapReduce#alon-Vostro-3300)2>
The problem is with "uuml" because in the XML file its apear with &uuml
Thanks for your help.
Hit the same error and found this in the ErlSom docs under limitations of the sax parser:
It doesn’t support entities, apart from the predefined ones (< etc.) and character references (&#nnn; and &#xhhh;).

How to create a file name with current date & time in lua?

I want to write a table into a file which named by the date and time it created.
I can open a file with hard coded name, write the table into it, like below:
FILENAME_EVENTS="Events.txt" -- filename in string
local fp=io.open(FILENAME_EVENTS, a) -- open a new file with the file name
io.output(FILENAME_EVENTS) -- redirect the io output to the file
-- write the table into the file
for i, e in ipairs(eventlist) do io.write(e.title, e.category, e.ds, e.de, e.td) end
But when I try to:
FILENAME_EVENTS=os.date().."\.txt" -- filename in string with date
local fp=io.open(FILENAME_EVENTS, a) -- open a new file with the file name
io.output(FILENAME_EVENTS) -- redirect the io output to the file
-- write the table into the file
for i, e in ipairs(eventlist) do io.write(e.title, e.category, e.ds, e.de, e.td) end
I got an error
bad argument #1 to 'output' (10/06/11 17:45:01.txt: Invalid argument)
stack traceback:
[C]: in function 'output'
Why this "10/06/11 17:45:01.txt" is an invalid argument? due to it contains spaces or '/'? Or any other reasons?
BTW, the platform is win7 Pro + Lua 5.1.4 for win
Apparently it's both / and : that bork. The first probably because it is regarded as directory separator. This can be demonstrated as below:
fn=os.date()..'.txt'
print(io.open(fn,'w')) -- returns invalid argument
fn=os.date():gsub(':','_')..'.txt'
print(io.open(fn,'w')) -- returns nil, no such file or directory
fn=os.date():gsub('[:/]','_')..'.txt'
print(io.open(fn,'w')) -- returns file(0x...), nil <-- Works
BTW, instead of using strange gsub and concatenation tricks, you might also consider using something like
fn=os.date('%d_%m_%y %H_%M.txt')

Resources