1
using (Stream stdin = Console.OpenStandardInput())
        {
            using (Stream stdout = Console.OpenStandardOutput())
            {
                byte[] buffer = new byte[2048];
                int bytes;
                while ((bytes = stdin.Read(buffer, 0, buffer.Length)) > 0)
                {
                    stdout.Write(buffer, 0, bytes);
                }
            }
        }

This code is a basic echo from the stdin to stdout, and it works when I write directly into the console. But when I try to write to the stdin using another program, in this case an AIR game using ActionScript 3, it isn't working.

I've launched the C# application using AS3's NativeProcess. It let's me start a process and access it's standard input/output. Reading from the stdout works fine, but writing to the stdin does nothing.

This is the AS3 code that writes to the stdin: The AS3 code for writing to the stdin

I got no clue why this isn't working. I've tried several different reading methods on the C# application but nothing captures the data I send via the stdin.

The C# applications stdin: The C# applications stdin

The C# applications stdout: The C# applications stdout

I'd appreciate any help as to why this isn't working. Thanks!

Orbit
  • 31
  • 6
  • Can you even *write* to `stdin`? In my head, `stdin` is read-only, while `stdout` and `stderr` are write only. Whenever I've wanted to glue them together I've used a pipe – Flydog57 Jul 19 '20 at 22:03
  • The question as asked makes no sense as you can't *write* into *input* of your own app... There is remote chance you are looking for https://stackoverflow.com/questions/2613161/how-to-write-to-the-stdin-of-another-app - some [edit] of the post may clarify what you are looking for. – Alexei Levenkov Jul 19 '20 at 22:14
  • standardInput is the output to the c# application while standardOutput is the input from the c# application. That's how the NativeProcess behaves, I'll add some pictures to clarify. – Orbit Jul 19 '20 at 22:53
  • Why using `writeUTF( value: "hello" );` instead of the correct `writeUTF( "hello" );`? Anyways is the problem solved by using **Net 3.5**? I'm seeing **Net 4.7** on my dev computer but haven't had a chance to try out your DLL issue yet (_eg:_ for this specific task it may really need version 3.5). I'll update when I get a chance. – VC.One Jul 20 '20 at 06:13
  • @Flydog57, **Read again** it says _`"write to the stdin using another program"`_. I think you assume C# started the process, but actually the other program is running this C# exe as a child process. From AS3 docs: `process.standardInput.writeUTF("foo");` (see [**communicating with an external process**](https://help.adobe.com/en_US/as3/dev/WSb2ba3b1aad8a27b060d22f991220f00ad8a-8000.html) section) because the [**AS3 manual**](https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/desktop/NativeProcess.html#standardInput) says _"Use this pipe to send data to this process."_. – VC.One Jul 20 '20 at 10:15
  • @AlexeiLevenkov Asker is not _"writing to their own program"_. This C# app will run as a child process from an AS3 app. In their shown C# code the `stdin.Read` part is reading input sent to it by the AS3 app that started it, then for further testing Asker communicates back to the parent (AS3 app) by using `stdout.Write`. I recommended [this way to them](https://stackoverflow.com/questions/62906471/as3-how-to-import-a-dll#comment111369152_62906471) because its how AS3 works (see also my above comment). Please vote to re-open. Thanks – VC.One Jul 20 '20 at 10:26

1 Answers1

1

It turns out you can't do this on the current .NET framework. You have to be on 3.5 or lower.

Here is the answer I found. AIR NativeProcess standardInput not connecting to app

Edit: Even after changing my .NET framework to 3.5 and even 3.0, I can't get this to work. I gave up after a full day of debugging, so I instead went ahead and implemented a simple TCP client on the C# app and a server in the flash game. Works flawlessly, but a bit unnecessary.

Orbit
  • 31
  • 6