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

I can not get stdin to work with grind #309

Open
kasperpeulen opened this issue Jan 29, 2016 · 8 comments
Open

I can not get stdin to work with grind #309

kasperpeulen opened this issue Jan 29, 2016 · 8 comments

Comments

@kasperpeulen
Copy link
Contributor

I have this task:

#!/usr/bin/env dart
import 'package:git/git.dart';
import 'package:grinder/grinder.dart';

... 

@Task()
Future<Null> createComponent() async {
  await stdin
      .map(SYSTEM_ENCODING.decode)
      .map((s) => s.trim())
      .forEach((component) async {
    new File('lib/components/$component.scss')..createSync();
    new File('lib/components/$component.html')..createSync();
    new File('lib/components/$component.dart')
      ..createSync()
      ..writeAsStringSync('''
import 'package:angular2/core.dart';

@Component(
    selector: '${component.replaceAll('_', '-')}',
    templateUrl: '$component.html',
    styleUrls: const ['$component.css']
)
class ${component.split('_').map((s) => s[0].toUpperCase() + s.substring(1)).join('')} {}
      ''');
    await runGit(['add', '--all']);
  });
}

For some reason this only works I have run the task like:
tool/grind.dart create-component
and not if I run it like:
grind create-component

Not sure if this is a pub bug or a grinder bug.

@zoechi
Copy link

zoechi commented Jan 29, 2016

I can not get stdin to work with grind

What's not working or what is happening differently than you expect? Any error message?

@zoechi
Copy link

zoechi commented Jan 29, 2016

If you run it with grind create-component it's running via pub global run and your script is executed in another process AFAIR. There are plans to make pub global run to create an isolate instead.

@kasperpeulen
Copy link
Contributor Author

So the stdin gives a stream of input from the terminal . Everytime you press enter, it gives you the byes of the input in the terminal.

This works if I run it like this:

tool/grind.dart create-component

But in the other case, it just never gives me any input. No error messages, the stream just never returns any byes from the input.

@devoncarew
Copy link
Contributor

It might be worth investigating whether a simple app run via pub global run can read from stdin (w/ the code above). You can use the --source path option to pub global activate to activate a local script. That would narrow down whether this is a pub issue or a grinder one -

@kasperpeulen
Copy link
Contributor Author

image

seems to work

@seaneagan
Copy link
Contributor

So I think the problem is that that the grind script is forwarding stdout and sterr as appropriate here, but it is not doing the same for stdin. I think we just need to add something like process.stdin.addStream(stdin);

@lexaknyazev
Copy link

Adding process.stdin.addStream(stdin); to bin/grinder.dart indeed helps.
Can the package be updated?

@devoncarew devoncarew added this to the project bootstrap milestone Jul 18, 2019
@vinzenzweber
Copy link

vinzenzweber commented Jul 13, 2021

I just stumbled upon this issue while implementing a grinder task. Is there any workaround available, or any plan to fix this issue?

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

6 participants