2

according to this answer

the dart:io libraries are only for the server/command-line, so they can't be compiled with dart2js.

is it possible to read from stdin and write to stdout with dart2js e.g:

$ java -jar ../../Downloads/rhino1_7R4/js.jar myjs.js < in.txt > out.txt

I'm considering editing the dart2js generated file and adding something like:

importPackage(java.io);
importPackage(java.lang);
scan = new BufferedReader( new InputStreamReader(System['in']) );
Community
  • 1
  • 1
Rusty Rob
  • 16,489
  • 8
  • 100
  • 116
  • Any luck on submissions in Dart? – Rohan Bojja Jun 08 '20 at 05:02
  • can't remember sorry - but you could maybe try do stdin using ajax in your dart code, and then when you compile to javascript, read from stdin and write to stdout - to do this, just replace the IO function (hint: use a string e.g. global obj, obj["my_io"] = ajaxfunc... then have a script that adds obj["my_io"] = stdinfunc.. – Rusty Rob Jun 08 '20 at 09:22

1 Answers1

1

dart2js is for running in the browser.
dart:io will not convert to JS because the browser doesn't support this functionality (like stdout/stdin).

Do you want to run JS generated from Dart running on the Server using Rhino? Maybe you could integrate the Dart VM in your app and run Dart code without transpiling to JS.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • websites such as codechef.com have support for rhino but not dart. I.E you upload your code file and they run your code. – Rusty Rob Jan 07 '14 at 06:15
  • I took just a brief look at their FAQ. I guess they are executing the code using stdin/stdout on the server and return just the result to the client. Can you please provide more information about what you are trying to achieve? – Günter Zöchbauer Jan 07 '14 at 06:20
  • I'd like to solve http://www.codechef.com/problems/TEST with dart. My current solution is to write my own dart2js compiler which replaces Dart Streams with Rhino BufferedReaders. – Rusty Rob Jan 07 '14 at 06:29
  • here are some sample answers: http://www.codechef.com/status/TEST?language=35&status=15&handle=&sort_by=All&sorting_order=asc&Submit=GO – Rusty Rob Jan 07 '14 at 06:30
  • 1
    I think I understand now what you are trying to achieve. Using JS-interop would be a first idea but I have no clue how to use this in a Dart code only app either. It could help to post your question at https://groups.google.com/a/dartlang.org too. – Günter Zöchbauer Jan 07 '14 at 06:41