Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-cmd and stdin (mac / linux) #4669

Closed
jcward opened this issue Nov 25, 2015 · 8 comments
Closed

-cmd and stdin (mac / linux) #4669

jcward opened this issue Nov 25, 2015 · 8 comments
Assignees

Comments

@jcward
Copy link
Contributor

jcward commented Nov 25, 2015

When using -cmd in an hxml file, it doesn't appear that STDIN is being redirected properly -- the program does not respond to user input.

This may be an hxcpp or haxelib problem, not sure. Perhaps related to #3859 (a different issue, but similar regarding i/o in -cmd mode), except that's neko/output and this is hxcpp/input. But I assume stdout redirection should affect all runtimes?

Here's a testcase, a simple CLI:

build.hxml

-main Main
-debug
-cpp export
-cmd export/Main-debug

Main.hx (note, neither readByte nor getChar work)

class Main {
  static function main() {
    while (true) {
      Sys.stdout().writeString("Something, or (q)uit ?\n");
      var i = Sys.getChar(true);
      //var i = Sys.stdin().readByte();
      trace(i);
      if (i==113) break;
    }
    trace("Goodbye!");
  }
}

Expected behavior: hitting keys should print keycodes, q should exit.

Observed behavior: hitting keys does nothing, ctrl-c is required to exit.

I tested both hxcpp and neko on linux and mac, both exhibit the problem. Simon tested windows and didn't see the issue.

If you launch the program standalone, it works as expected. Just not when launched via -cmd

@Simn
Copy link
Member

Simn commented Nov 25, 2015

For what it's worth this works fine for me on Windows.

@jcward
Copy link
Contributor Author

jcward commented Nov 25, 2015

Thanks, @Simn. I tested mac and it's also broken there. I'll update the bug description.

@jcward jcward changed the title -cmd and stdin -cmd and stdin (mac / linux) Nov 25, 2015
@Simn
Copy link
Member

Simn commented Dec 3, 2015

I can reproduce the problem on Linux.

@ncannasse
Copy link
Member

Does it works after you hit enter?

@Simn
Copy link
Member

Simn commented Dec 3, 2015

No.

@ncannasse
Copy link
Member

Uhm, that seems normal: we're using Unix.open_process_full in main.ml/run_command and are not redirecting our stdin to the process stdin.

We instead need to create new pout/perr pipes and use create_process, as shown is
http://stackoverflow.com/questions/26982027/why-is-open-process-full-not-returning-the-stdout-contents-of-the-externam-proce

I'll leave @Simn to implement + test on Windows/Linux

@ncannasse ncannasse assigned Simn and unassigned ncannasse Dec 4, 2015
@Simn
Copy link
Member

Simn commented Dec 4, 2015

It's pretty awkward for me to test this through my Ubuntu VM. Maybe @waneck could help out here?

@jcward
Copy link
Contributor Author

jcward commented Dec 4, 2015

I could potentially validate a change on Ubuntu. You could send me a branch, patch, or updated main.ml.

@Simn Simn assigned waneck and unassigned Simn Dec 4, 2015
@Simn Simn modified the milestone: 3.4 Feb 23, 2016
aarentoft added a commit to aarentoft/SpotifyController that referenced this issue Jun 29, 2016
Note the change in test.hxml. "-x TestClient" cannot be used when
Sys.stdin() is in the source code as -x utilizes the -cmd internally.
-cmd does not work with Sys.stdin() (see
HaxeFoundation/haxe#4669). Use
'haxe test.hxml && neko TestClient.n' as a testing one-liner.
@Simn Simn modified the milestones: 3.4, 4.0 Jan 9, 2017
@Simn Simn modified the milestones: Release 4.0, Bugs Apr 17, 2018
@RealyUniqueName RealyUniqueName modified the milestones: Bugs, Hotfix Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants