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

Redirect Console.WriteLine output to repl console #96

Open
marckruzik opened this issue Feb 8, 2024 · 3 comments
Open

Redirect Console.WriteLine output to repl console #96

marckruzik opened this issue Feb 8, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@marckruzik
Copy link

We are using dotnet-repl to automate .dib notebooks as a replacement for scripts (.bat script, .sh scripts), as part of our DevOps revamping.
As we are C# developers, using C# as a scripting language and notebooks as a scripting environment is a huge boost to our productivity.

We are using with command lines such as:

dotnet repl --run main.dib --exit-after-run --output-path output.ipynb --output-format ipynb

We are running those command lines through tools such as Jenkins, or Windows batch. I know about the ipynb output, but it works as a black box, as there is no real time direct display from dotnet-repl to the console.
Any fail forces to connect to the distant machine, launch VSCode and look into the notebook to debug.
Besides, some execution can be long, and with no console output, we are left in the dark. Is it blocked by something? Is it reaching at least the first step?

It would be really helpful, if there was some way to display information from the notebook to the console using dotnet-repl.
Maybe there could be some way to redirect the notebook Console.WriteLine output / standard output to the dotnet-repl console?

I would like to do the following:

  • I write in the notebook Console.WriteLine("Hello");
  • I launch a Windows CMD console
  • I type dotnet repl --run main.dib --exit-after-run --output-console
  • the notebook is executed
  • "Hello" is displayed

This is a feature which will allow dotnet-repl to be used far more in our company, and by other devops as well.

@jonsequitur
Copy link
Owner

This is a great proposal, and probably doesn't require redirecting console output.

.NET Interactive already captures console output and transforms it into a stream of events (Kernel.KernelEvents). Those events include other display events (DisplayedValueProduced, DisplayedValueUpdated, ErrorProduced, ReturnValueProduced, StandardErrorValueProduced, and StandardOutputValueProduced) and to fully see work in progress, it would be useful to write something to the terminal for all of these, not just ones that capture console output (i.e. the last two).

Writing some form of feedback to the terminal based on these events should be fairly simple. It's what dotnet repl is already doing when running in interactive mode. It's also possible to include a cell execution number (KernelCommandCompletionEvent.ExcecutionOrder). This could provide a progress indicator such as Executing cell x of y.

@jonsequitur jonsequitur added the enhancement New feature or request label Feb 12, 2024
@marckruzik
Copy link
Author

This could provide a progress indicator such as Executing cell x of y.

Providing a progress indicator would be really interesting. The difficulty I see is to manage imports.
Notebook A has three cells, and its cell A1 imports Notebook B which contains 2 cells.

Executing A1 of 3
Executing B1 of 2
Executing B2 of 2
Executing A2 of 3
Executing A3 of 3

it would be useful to write something to the terminal for all of these

I agree. For now, the main improvement would be to display the main stream on console StandardOutputValueProduced. Displaying StandardErrorValueProduced will be incredibly helpful.
About error management, the stack trace gives the name of the C# methods. And with the progress indicator we are talking about, we will become able to see at which cell the problem is.

@jonsequitur
Copy link
Owner

I wouldn't special case console output. Other display events (e.g. someValue.Display();) are used at least as often in notebooks I see, and displays produced internally (including compilation errors) don't go via Console.Write.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants