Visual Studio Code 在调试时重定向输入 [英] Visual Studio Code redirect input on debug

查看:85
本文介绍了Visual Studio Code 在调试时重定向输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序正在从标准输入读取:

My application is reading from stdin:

var input = process.stdin.read();

是否可以将 Visual Studio Code 配置为在调试时重定向输入?

Is it possible to configure Visual Studio Code to redirect input on debug?

所以它等于这个命令行:

So it is be equal to this command line:

node app.js < input.txt

此配置无效,调试未启动.

This configuration is not working, and debug is not starting.

{
  "name": "Launch",
  "type": "node",
  "program": "app.js",
  "stopOnEntry": false,
  "args": [
    "<",
    "input.txt"
  ]
}

推荐答案

args 数组一般用于 Node.js 启动和 V8 引擎运行时标志.

The args array is generally for Node.js startup and V8 engine runtime flags.

  --no-deprecation
  --throw-deprecation
  --trace-deprecation
  --v8-options
  --max-stack-size=val
  --icu-data-dir=dir

  --enable-ssl2
  --enable-ssl3

在命令行中输入 node --v8-options 以查看 V8 运行时标志的完整列表.

Type node --v8-options at the command line to see the full list of V8 runtime flags.

我建议您从命令行使用调试标志启动您的应用程序,以便您可以将其引导至 stdin,然后将调试器附加到您正在运行的进程中.

I'd recommend you start your application with the debug flag from the command line so you can direct it to take stdin and then attach the debugger to your running process.

> node --debug app.js
Debugger listening on port 5858

您的 launch.json 文件中可以有多个配置.添加或修改一个作为您的附加"调试配置.对于附加,必须指定地址"和端口"(请注意,由于尚不支持远程调试,因此必须将地址"设置为本地主机").端口应该是上面调试启动过程返回的那个.

You can have multiple configurations in your launch.json file. Add or modify one to be your "Attach" debug configuration. For attaching, "address" and "port" must be specified (please note that "address" must be set to "localhost" since remote debugging is not yet supported). Port should be the one that the debug startup process returned above.

一旦您的应用程序在指定的端口上运行,您就可以在播放/运行图标旁边的下拉列表中更改调试目标.

Once your application is running on the port specified, you can change the debug target in the dropdown next to the play/run icon.

这篇关于Visual Studio Code 在调试时重定向输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆