You seemed to have a misunderstanding about how pipe works. A pipe has a typical 4k buffer so you can write more than one byte to it. You tried hard to write one byte a time to the pipe (which is not necessary), but in your grab_a_byte function, you used "cat $INPUT" to drain everything which should be just a byte at a time. Either use "read -n 1" as you did in other places or use "dd bs=1 count=1" to grab one byte from the pipe.
You seemed to have a misunderstanding about how pipe works. A pipe has a typical 4k buffer so you can write more than one byte to it. You tried hard to write one byte a time to the pipe (which is not necessary), but in your grab_a_byte function, you used "cat $INPUT" to drain everything which should be just a byte at a time. Either use "read -n 1" as you did in other places or use "dd bs=1 count=1" to grab one byte from the pipe.
No, you see: I haven't tried to "write one byte at a time", what I'm trying to do is READ one byte at a time. cat ${INPUT} is not "in the grab_a_byte" function, it's in the listen function. cat ${INPUT} does dump the contents of INPUT, but does not close INPUT afterwards (because of keep_fifo_open), and I did pipe it into while IFS= read -n 1 in the listen function.
---------- Post updated at 05:12 PM ---------- Previous update was at 05:07 PM ----------
In case you didn't notice: the listen function is supposed to dump one byte from ${INPUT} at a time into ${FIFO}; therefor, in grab_bytes, cat ${FIFO} SHOULD output only ONE byte.
---------- Post updated at 05:16 PM ---------- Previous update was at 05:12 PM ----------
The idea is basically to have a data stream, a named pipe in this case, constantly open for input. This data stream has to be available at all times, to be able to receive input. And the script is supposed to be able to grab one byte at a time from this stream, without ever closing it. Those are the conditions I'm trying to satisfy with this script: all of them.
---------- Post updated at 07:02 PM ---------- Previous update was at 05:16 PM ----------
Hmm... interestingly, when I limit yap_randomly to [a-z] bytes, thus:
...the script works as it should. Maybe there is a set of specific bytes (from 0x00 to 0xFF) which cause the script to malfunction.
---------- Post updated 12-31-12 at 03:10 AM ---------- Previous update was 12-30-12 at 07:02 PM ----------
Ok. This pretty much solves the "forbidden bytes" problem:
The script is now perfect. Thanks everyone for your support and constructive criticism.
---------- Post updated at 03:24 AM ---------- Previous update was at 03:10 AM ----------
Here's a final, fully functional, version of the script, in case anybody wants to put it to some good use, or to modify it:
EDIT: The script isn't perfect... the character '\' (0x5C) doesn't get printed for some reason... it's probably getting parsed. Well, I'll look into that some other time. I guess this is enough for now.
EDIT2: read just needs the -r option. NOW it's ready.
EDIT3: nah, not perfect. byte 0xC5 also fails...
---------- Post updated at 03:55 PM ---------- Previous update was at 03:24 AM ----------
Well, I wasn't aware of this, but apparenty read forbids a certain set of bytes from being stored in a variable, and dd has trouble receiving newline characters when used thus:
So, I opted for od, and now the script takes in ANY byte (from 0x00 to 0xFF):
Yup... it's pretty much perfect now. Perhaps with a few boundary issues, such as: what happens if someone requesets more bytes than have been inputted into the INPUT named pipe (i.e., pressing "p" one too many times)? Currently, the script just gets stuck indefinitely waiting for more input to be dumped into INPUT; you can "un-stuck" it by shooting more bytes into INPUT from another process, but, well, maybe I should add a timeout or something like that. Anyway: it's finished. You can try it if you want, just remember to substitute the listen function with the one that uses od.
hi all,
I wish to calculate the length between intervals whose are defined by a starting and an end possition. The data looks like this:
1 10
23 30
45 60
70 100...
The desired output should be:
13 # (23-10)
15 # (45-30)
10 # (70-60)...
I donīt know how to operate with different... (2 Replies)
Hello
I created 3 files by:
dd if=/dev/urandom bs=1024 count=1000000 of=./testfile1
dd if=/dev/urandom bs=1024 count=5000000 of=./testfile2
dd if=/dev/urandom bs=1024 count=10000000 of=./testfile3
Now I want to know how to make a change in a specific byte and/or line of theses files? (2 Replies)
Hi all,
I hope you can help me with the following question:
I have multiple tables like this:
Chr Start End Zygosity Gene
chr1 153233510 153233510 het LOR
chr1 153233615 153233615 hom LOR
chr1 153233701 153233701 hom LOR
chr1 ... (5 Replies)
There was an upload recently on generating a pseudo-random file when /dev/random does NOT exist.
This does not need /dev/random, /dev/urandom or $RANDOM either...
(I assume $RANDOM relies on the /dev/random device in some way.)
This code uses hexdump just because I like hexdump for ease of... (2 Replies)
Need to use dd to generate a large file from a sample file of random data. This is because I don't have /dev/urandom.
I create a named pipe then:
dd if=mynamed.fifo do=myfile.fifo bs=1024 count=1024
but when I cat a file to the fifo that's 1024 random bytes:
cat randomfile.txt >... (7 Replies)
Hi
I am new to expect. Please if any one can help on my issue its really appreciable. here is my issue:
I want expect script for random passwords and random commands generation.
please can anyone help me?
Many Thanks in advance (0 Replies)
divide input values into specified number (-100 or -200) according to the key (a1 or a2 ....)
For ex: if we give -100 in the command line it would create 100 number intervals (1-100, 100-200, 200-300) untill it covers the value 300 in a1.
Note: It should work the same even with huge numbers... (3 Replies)
Hi All
Can anyone please suggest me how to remove the last byte from a falt file .This is from the last line's last BYTE.
Please suggest me something.
Thank's and regards
Vinay (1 Reply)
In my server migration requirement, I need to compare if one file on old server is exactly the same as the corresponding file on the new server.
For diff and comm, the inputs need to be sorted. But I do not want to disturb the content of the file and need to find byte-to-byte match.
Please... (4 Replies)
I posted a question on date intervals about a month back asking about how I could be able to go about a user entering the starting year/month/day and an ending year/month/day and then the script automatically cycling through each day of each month of each year that the user has specified.
I... (7 Replies)