Skip to contentSkip to conversation

piping escape into dosemu

DISCUSSION Mike McCarty 3 participants 15 messages Mar 5, 2010 – Mar 11, 2010 3 messages not in the archive

lore
Share & tools
lore
#0 lore raw

Meant for the whole group to see the answer I gave. Sorry

-------- Original Message --------
Subject: Re: piping escape into dosemu
Date: Fri, 05 Mar 2010 12:49:59 -0600
From: Mike McCarty <[email protected]>
To: solarflow99 <[email protected]>
References: <[email protected]> <[email protected]> <[email protected]>

Quoted 2 lines · solarflow99 wrote:

hmm, i'm not really sure myself, if no one knows here, maybe you will have to ask the dosemu-devel list.

$ man echo

NAME
echo - display a line of text

SYNOPSIS

       echo [OPTION]... [STRING]...

[...]

-e enable interpretation of the backslash-escaped
characters
listed below

[...]

\NNN the character whose ASCII code is NNN (octal)

[...]

$ echo "\033" > dospipe
Quoted 50 lines · TW
Quoted 33 lines

Sorry, can't anybody give me a hint about this? Is there more documentation on the commands that can be piped into dosemu (especially the keystroke command, of course)?

Thanks!
Thomas W.

2010/2/25 TW <[email protected]>:

Quoted 24 lines

Hi all,

I'm sorry, the crappy webmail service of my e-mail provider messed up my last message, so here it is again from a different mail account:

I'm using the -U switch to pipe keyboard input into dosemu. I'm starting dosemu like

dosemu -U dospipe

and can then pipe keystrokes like

echo "keystroke dir\r" > dospipe

Are all keystrokes encoded the same way as described for the -input switch[1]? I'm trying to pipe the escape key, but

echo "keystroke \^[" > dospipe

doesn't seem to do anything. Any suggestions? By the way, how can I pipe a single space character?

Thanks in advance!

Quoted 9 lines
Quoted 4 lines

Thomas W.

[1] http://dosemu.sourceforge.net/docs/README/1.4/x724.html#AEN748

--
To unsubscribe from this list: send the line "unsubscribe linux-msdos" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-msdos" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 13 lines
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
Oppose globalization and One World Governments like the UN.
This message made from 100% recycled bits.
You have found the bank of Larn.
I speak only for myself, and I am unanimous in that!


-- 
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
Oppose globalization and One World Governments like the UN.
This message made from 100% recycled bits.
You have found the bank of Larn.
I speak only for myself, and I am unanimous in that!
#1 lore raw

Hi Mike,

Quoted 10 lines

From: Mike McCarty <[email protected]>

$ man echo

[...]

      -e     enable   interpretation  of  the  backslash-escaped characters
             listed below

sorry if I totally misinterpret your post, but I think I do *not* want to enable the escaped characters because the keystroke command obviously expects to read the escape sequence, not the ascii value that results from it. Otherwise you would for example not be able to send a carriage return, i.e.

echo "keystroke \r" > dospipe

results in a carriage return in dosemu while

echo -e "keystroke \r" > dospipe

does not.

I'm just using echo here because it's easily reproducible by everyone.
I'm successfully using Ruby to remote control dosemu, but I can't
pipe the escape key for the named reasons, neither through echo nor Ruby or whatever I may chose. Maybe there is a syntax that allows me to pipe ASCII codes (e.g. 27 or hex 1B or octal 033 for the escape key) into Dosemu, but I can't find it anywhere. The readme says something about \^[:

\^x <Ctrl>x, where X is one of the usual C,M,L,[ ...
(e.g.: \^[ == <Ctrl>[ == ESC )

but I don't have luck with this. I tried several escape sequences that could possibly be used, like \0x1B, \x1B, \033, \0033, still nothing. What am I missing??

Thomas W.
--
To unsubscribe from this list: send the line "unsubscribe linux-msdos" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

One P.S.:

2010/3/6 TW <[email protected]>:

Quoted 5 lines

[...] I do *not* want
to enable the escaped characters because the keystroke command obviously expects to read the escape sequence, not the ascii value that results from it.  Otherwise you would for example not be able to send a carriage return,

That's of course not really correct, as

echo -e "keystroke \\\r" > dospipe

does the job, but I hope you understand what I'm trying to say. As I want to pipe the sequences, not the ASCII values, there is no need to use the -e switch, is there?
--
To unsubscribe from this list: send the line "unsubscribe linux-msdos" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
In reply to TW

TW wrote:

Oh, I forgot how to pipe a single space character

echo -n " " > dospipe

Quoted 8 lines

Hi Mike,

Quoted 6 lines

From: Mike McCarty <[email protected]>

$ man echo

[...]

Quoted 8 lines
Quoted 4 lines

-e enable interpretation of the backslash-escaped
characters
listed below

sorry if I totally misinterpret your post, but I think I do *not* want to enable the escaped characters because the keystroke command obviously expects to read the escape sequence, not the ascii value

I can't make sense out of this. You seem to be referring to a numeral or something, but I can't tell. What do you mean by "the ascii value that results from it"?

Please consider these results:

$ echo -n "033" | wc
      0       1       3
$ echo -n "\033" | wc
      0       1       4
$ echo -ne "\033" | wc
      0       0       1

The first example passes three characters as output. They are '0', '3', and '3'.
The second example passes four characters as output. They are BACKSLASH, '0', '3', and '0'.
The third example passes one character as output, which is the ESC character.

Isn't that what you want?

Quoted 2 lines

that results from it. Otherwise you would for example not be able to send a carriage return, i.e.

I don't understand your objection. Do you or do you not want the ESC character to appear in the input?

Quoted 8 lines

echo "keystroke \r" > dospipe

results in a carriage return in dosemu while

echo -e "keystroke \r" > dospipe

does not.

The -e enables conversion of the escape sequences of three digit octal numbers into single characters in the output stream.

Quoted 7 lines

I'm just using echo here because it's easily reproducible by everyone.
I'm successfully using Ruby to remote control dosemu, but I can't
pipe the escape key for the named reasons, neither through echo nor Ruby or whatever I may chose. Maybe there is a syntax that allows me to pipe ASCII codes (e.g. 27 or hex 1B or octal 033 for the escape key) into Dosemu, but I can't find it anywhere. The readme says something about \^[:

You are using words in a way which is not consistent with a single interpretation of each word.

Quoted 6 lines

\^x <Ctrl>x, where X is one of the usual C,M,L,[ ...
(e.g.: \^[ == <Ctrl>[ == ESC )

but I don't have luck with this. I tried several escape sequences that could possibly be used, like \0x1B, \x1B, \033, \0033, still nothing. What am I missing??

I don't know. It's difficult to interpret your language.

Let's try this. How about you describe, in careful detail, what you want to happen, then describe in detail what you did, and then describe in detail what you observed.

I have so far interpreted your request along these lines

I want an application running in a DOSEMU environment to behave as if it received a hand typed ESC character.

I have tried using a pipe. I have used the echo command in this manner

echo -ne "\033" > dospipe

and what the program running received was [fill in the blank].

Mike

Signature · 5 lines
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
Oppose globalization and One World Governments like the UN.
This message made from 100% recycled bits.
You have found the bank of Larn.
I speak only for myself, and I am unanimous in that!
#4 lore raw
Quoted 9 lines · Mike McCarty

Please consider these results:

$ echo -n "033" | wc
      0       1       3
$ echo -n "\033" | wc
      0       1       4
$ echo -ne "\033" | wc
      0       0       1
Quoted 4 lines

The first example passes three characters as output. They are '0', '3', and '3'.
The second example passes four characters as output. They are BACKSLASH, '0', '3', and '0'.

I can't believe that typo! I'm so sorry. The characters are BACKSLASH, '0', '3', and '3'. So sorry for any confusion.

Mike

Signature · 5 lines
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
Oppose globalization and One World Governments like the UN.
This message made from 100% recycled bits.
You have found the bank of Larn.
I speak only for myself, and I am unanimous in that!
#5 lore raw
In reply to Mike McCarty

Hi Mike,

thanks for your patience. I'm sorry if my wording was confusing - English is not my mother tongue.

It appears the following problem is equivalent to mine, but simpler to describe because it neither involves pipes nor echo:

Say I have a DOS program that shows kind of a splash screen which can be bypassed by hitting ESC. (This is just an example.) I'd like to automate this, so I start dosemu like

dosemu -input 'thedosapp.exe\r\^['

because in the readme[1] I'm told that "\^[" is the syntax for the escape key. At least that's how I interpret the "\^x" section. Unfortunately, this doesn't work. So what's the syntax for the escape key? I tried to find hints in the source code, but my C know-how is pretty basic. All I figured out is that the uhook_keystroke() function in dosemu/src/base/misc/userhook.c must be the function that handles the keystroke command.

2010/3/8 Mike McCarty <[email protected]>:

Quoted 6 lines

TW wrote:

Oh, I forgot how to pipe a single space character

       echo -n " " > dospipe

I sorted at least this one out, it can be achieved like

echo "\ \ " > dospipe

Thomas W.

[1] http://dosemu.sourceforge.net/docs/README/1.4/x724.html#AEN748
[2] http://dosemu.sourceforge.net/docs/README-tech/0.98/README-tech-2.html
--
To unsubscribe from this list: send the line "unsubscribe linux-msdos" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
Quoted 4 lines · TW

Hi Mike,

thanks for your patience. I'm sorry if my wording was confusing - English is not my mother tongue.

No problem.

Quoted 11 lines

It appears the following problem is equivalent to mine, but simpler to describe because it neither involves pipes nor echo:

Say I have a DOS program that shows kind of a splash screen which can be bypassed by hitting ESC. (This is just an example.) I'd like to automate this, so I start dosemu like

dosemu -input 'thedosapp.exe\r\^['

because in the readme[1] I'm told that "\^[" is the syntax for the escape key. At least that's how I interpret the "\^x" section.

Ok, we have a use/mention problem, I think. In your example, you give a string enclosed in 'single quotes'. That string, as you show it, should have two characters after the '\r'. I suspect that you are typing three characters '\', '^', and '['. That is not the intended action. What is intended is that you type a BACKSLASH ('\'), and an ESC. The shell displays on your screen two characters when you type ESC, but that is a single keystroke.

You may have to type ESC twice to make it work with your shell. In any case, you should not be typing the '^' and '[' characters; those are just how the shell displays the input on the screen.

Quoted 2 lines

Unfortunately, this doesn't work. So what's the syntax for the escape key? I tried to find hints in the source code, but my C know-how is

The ESC key. You may, as I said, have to type it twice. I had to.

Quoted 3 lines

pretty basic. All I figured out is that the uhook_keystroke() function in dosemu/src/base/misc/userhook.c must be the function that handles the keystroke command.

Well, let's hope that gets you going!

Mike

Signature · 5 lines
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
Oppose globalization and One World Governments like the UN.
This message made from 100% recycled bits.
You have found the bank of Larn.
I speak only for myself, and I am unanimous in that!
#7 lore raw

2010/3/9 Mike McCarty <[email protected]>:

Quoted 5 lines
Quoted 4 lines · TW

[...] I start dosemu like

 dosemu -input 'thedosapp.exe\r\^['

Quoted 9 lines
Quoted 2 lines

because in the readme[1] I'm told that "\^[" is the syntax for the escape key.  At least that's how I interpret the "\^x" section.

[...] I suspect
that you are typing three characters '\', '^', and '['. That is not the intended action. What is intended is that you type a BACKSLASH ('\'), and an ESC. The shell displays on your screen two characters when you type ESC, but that is a single keystroke.

O.K., I'm beginning to understand what you're talking about. Up to now I didn't really use anything but bash. At least for me, pressing the escape key (however often) does not display anything, but when trying sh and dash, I see that pressing ESC "visually" resuts in ^[. And yes, now something like

dosemu -input 'thedosapp.exe\r\^['

indeed works, many thanks for pointing me to this! Unfortunately, for some reason this only works with the -input switch, but not when piping, like

echo "keystroke \^[" > dospipe

(where ^[ is what results from pressing ESC). It doesn't work through dosctrl or Ruby either. I wonder why this is supported by the -input switch, but not by the keystroke command...

Quoted 7 lines
Quoted 4 lines

pretty basic.  All I figured out is that the uhook_keystroke() function in dosemu/src/base/misc/userhook.c must be the function that handles the keystroke command.

Well, let's hope that gets you going!

I may try to find out more, but I believe fixing it (i.e. making the string representing a piped keystroke sequence is parsed in the same manner that a keystroke string passed on the command line is) will be beyond my possibilities.

Thanks for your help!

Thomas
--
To unsubscribe from this list: send the line "unsubscribe linux-msdos" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw
Quoted 15 lines · TW

2010/3/9 Mike McCarty <[email protected]>:

Quoted 5 lines
Quoted 4 lines · TW

[...] I start dosemu like

dosemu -input 'thedosapp.exe\r\^['

Quoted 8 lines
Quoted 2 lines

because in the readme[1] I'm told that "\^[" is the syntax for the escape key. At least that's how I interpret the "\^x" section.

[...] I suspect
that you are typing three characters '\', '^', and '['. That is not the intended action. What is intended is that you type a BACKSLASH ('\'), and an ESC. The shell displays on your screen two characters when you type ESC, but that is a single keystroke.

Quoted 4 lines

O.K., I'm beginning to understand what you're talking about. Up to now I didn't really use anything but bash. At least for me, pressing the escape key (however often) does not display anything, but when trying sh and dash, I see that pressing ESC "visually" resuts in ^[.

$ set | grep SHELL
SHELL=/bin/bash
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
$ /bin/bash --version
GNU bash, version 2.05b.0(1)-release (i386-redhat-linux-gnu)
Copyright (C) 2002 Free Software Foundation, Inc.

Perhaps something in SHELLOPTS is different, and modifies that behavior.

Quoted 9 lines

And yes, now something like

dosemu -input 'thedosapp.exe\r\^['

indeed works, many thanks for pointing me to this! Unfortunately, for some reason this only works with the -input switch, but not when piping, like

echo "keystroke \^[" > dospipe

Please note that "some string" and 'some string' are NOT the same. However, in this case, I don't see what difference it would make.

Quoted 8 lines

(where ^[ is what results from pressing ESC). It doesn't work through dosctrl or Ruby either. I wonder why this is supported by the -input switch, but not by the keystroke command...

I may try to find out more, but I believe fixing it (i.e. making the string representing a piped keystroke sequence is parsed in the same manner that a keystroke string passed on the command line is) will be beyond my possibilities.

I'm not ready to throw in the towel. If we keep plugging at it, I think we can get there.

Quoted 1 line

Thanks for your help!

What do you get when you do this:

$ echo -n "^[" | wc
      0       0       1

Do you get the " 0 0 1" output I do? If so, then we can get there. Or try

$ echo -n '^[' | wc
      0       0       1

Mike

Signature · 5 lines
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
Oppose globalization and One World Governments like the UN.
This message made from 100% recycled bits.
You have found the bank of Larn.
I speak only for myself, and I am unanimous in that!
#9 lore raw

2010/3/11 Mike McCarty <[email protected]>:

Quoted 9 lines
Quoted 4 lines

Up to
now I didn't really use anything but bash.  At least for me, pressing the escape key (however often) does not display anything, but when trying sh and dash, I see that pressing ESC "visually" resuts in ^[.

$ set | grep SHELL
SHELL=/bin/bash
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
Quoted 6 lines
$ /bin/bash --version
GNU bash, version 2.05b.0(1)-release (i386-redhat-linux-gnu)
Copyright (C) 2002 Free Software Foundation, Inc.

Perhaps something in SHELLOPTS is different, and modifies that behavior.

I'm now using sh for the tests, which properly shows the ESC, so this bash/ESC thing is only a side show. I can see nothing wrong with my bash, though:

tom@tom-desktop:~$ set | grep SHELL
SHELL=/bin/bash
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
tom@tom-desktop:~$ /bin/bash --version
GNU bash, Version 4.0.33(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
Lizenz GPLv3+: GNU GPL Version 3 oder jünger <http://gnu.org/licenses/gpl.html>

Dies ist freie Software. Sie darf verändert und verteilt werden. Für dieses Programm besteht keinerlei Garantie.

I'm running it on Ubuntu Karmic, 64 bit. No matter if I run bash in gnome-terminal or on a text terminal (e.g. on Alt-Ctrl-F1), nothing is displayed. sh and dash do it in both cases.

Quoted 2 lines

Please note that "some string" and 'some string' are NOT the same.

Thanks for that hint, I didn't give this any attention yet. (I guess there's still a lot to learn about the shell for me!)

Quoted 4 lines

I'm not ready to throw in the towel. If we keep plugging at it, I think we can get there.

Your persistence is impressive :-).

Quoted 6 lines

What do you get when you do this:

$ echo -n "^[" | wc
     0       0       1

With sh or dash, I get the exact same output.

Thomas
--
To unsubscribe from this list: send the line "unsubscribe linux-msdos" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw
In reply to TW

TW wrote:

[...]

Quoted 8 lines

And yes, now something like

dosemu -input 'thedosapp.exe\r\^['

indeed works, many thanks for pointing me to this! Unfortunately, for some reason this only works with the -input switch, but not when piping, like

Quoted 5 lines

echo "keystroke \^[" > dospipe

(where ^[ is what results from pressing ESC). It doesn't work through dosctrl or Ruby either. I wonder why this is supported by the -input switch, but not by the keystroke command...

To get back to the use of the echo command...

$ echo -n "\033" | wc
      0       1       4
$ echo -ne "\033" | wc
      0       0       1

This looks like a singe ESC character got sent to the output, to me.

In fact...

$ echo -ne "\033" | od -x
0000000 001b
0000001

So, od got exactly one character, which was an ESC.

Mike

Signature · 5 lines
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
Oppose globalization and One World Governments like the UN.
This message made from 100% recycled bits.
You have found the bank of Larn.
I speak only for myself, and I am unanimous in that!
#11 lore raw

2010/3/11 Mike McCarty <[email protected]>:

Quoted 9 lines

In fact...

$ echo -ne "\033" | od -x
0000000 001b
0000001

So, od got exactly one character, which was an ESC.

O.K., one more pitfall. Obviously, the shells use their own internal echo and don't call /bin/echo. sh and dash give me

$ echo -ne "\033" | od -x
0000000 6e2d 2065 0a1b
0000006

i.e. echo is actually echoing the switch "-ne", followed by a space, ESC and newline. In bash, I get

tom@tom-desktop:~$ echo --version
--version
tom@tom-desktop:~$ /bin/echo --version
echo (GNU coreutils) 7.4
Copyright © 2009 Free Software Foundation, Inc.
Lizenz GPLv3+: GNU GPL Version 3 oder höher <http://gnu.org/licenses/gpl.html>
Dies ist freie Software: Sie können sie ändern und weitergeben.
Es gibt keinerlei Garantien, soweit wie es das Gesetz erlaubt.

Geschrieben von Brian Fox und Chet Ramey.

I'll be using /bin/echo now to make sure the same echo is used in bash and sh. --
To unsubscribe from this list: send the line "unsubscribe linux-msdos" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#12 lore raw

Hi TW,
You might want to investigate the command 'printf', it's rarely implemented
by the shell and has consistent behaviour (no implicit NL etc) across different platforms. For that reason many shell script writers shy away from echo and use printf instead. See man 1 printf for details.

Hope that helps,

Andrew

Quoted 29 lines · TW

2010/3/11 Mike McCarty <[email protected]>:

Quoted 7 lines

In fact...

$ echo -ne "\033" | od -x
0000000 001b
0000001

So, od got exactly one character, which was an ESC.

O.K., one more pitfall. Obviously, the shells use their own internal echo and don't call /bin/echo. sh and dash give me

$ echo -ne "\033" | od -x
0000000 6e2d 2065 0a1b
0000006

i.e. echo is actually echoing the switch "-ne", followed by a space, ESC and newline. In bash, I get

tom@tom-desktop:~$ echo --version
--version
tom@tom-desktop:~$ /bin/echo --version
echo (GNU coreutils) 7.4
Copyright © 2009 Free Software Foundation, Inc.
Lizenz GPLv3+: GNU GPL Version 3 oder höher
<http://gnu.org/licenses/gpl.html> Dies ist freie Software: Sie können sie
ändern und weitergeben.
Es gibt keinerlei Garantien, soweit wie es das Gesetz erlaubt.
Quoted 7 lines

Geschrieben von Brian Fox und Chet Ramey.

I'll be using /bin/echo now to make sure the same echo is used in bash and sh. --
To unsubscribe from this list: send the line "unsubscribe linux-msdos" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-msdos" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw

2010/3/11 Andrew Bird (Sphere Systems) <[email protected]>:

Quoted 6 lines

Hi TW,
       You might want to investigate the command 'printf', it's rarely implemented by the shell and has consistent behaviour (no implicit NL etc) across different platforms. For that reason many shell script writers shy away from echo and use printf instead. See man 1 printf for details.

Thanks for the tip. I'm learning more about the shell here than about the actual problem :-). Unfortunatley, in the end I don't want to use the shell at all for this specific task!

Thomas W.
--
To unsubscribe from this list: send the line "unsubscribe linux-msdos" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#17 lore raw

Thanks all for your effort to help me! I accidentally didn't reply to the list, so here it is again:

2010/3/11 Alain Mouette <[email protected]>:

Quoted 8 lines

To make sure that it works allways the same, use explicit external:

$ /bin/echo -ne "\033" | od -x
0000000 001b
0000001

It does.

So back to my original problem: I want to achieve the same effect that I can with

dosemu -input 'thedosapp.exe\r\^['

The actual byte sequence that sh passes to dosemu as argument after -input is

74 68 65 64 6f 73 61 70 70 2e 65 78 65 5c 72 5c 1b

I can get the exact same byte sequence with

/bin/echo -n 'thedosapp.exe\r\['

For the keystroke command that's piped I need a newline at the end, so I omit -n and use

/bin/echo 'keystroke thedosapp.exe\r\^[' > dospipe

Everything gets through except for the ESC. I guess this is the end of the song.

Alain suggested later:

2010/3/11 Alain Mouette <[email protected]>:

Quoted 5 lines

Have you tried using 2 ESCs ? maybe you get one at the other ent... this happens so many linux programas...

Unfortunately still no success. I suspect the string that's piped is parsed somewhat differently from the string that's passed on the command line, and this can only be fixed in the source code.

Thomas Weber