在 Visual Studio(或其他 JS 调试器)中调试 Javascript

发布于 2025-01-06 08:57:38 字数 917 浏览 5 评论 0原文

我有一个 .js 文件,通常由 cscript.exe 执行(即不在浏览器中运行并且无法在那里运行)。

我知道,我可以向 cscript.exe 提供 //X 参数,以便要求选择调试器。好的。没关系。

我选择“Visual Studio 2005 调试器”,IDE 出现,执行在第一行停止。美好的。

脚本终止(或者我终止它),我编辑了一些内容并想再次调试它。

简单的想法就是点击 F5 并再次运行调试器。但这行不通。 VS 只是告诉我它在 cscript.exe 中找不到任何调试符号: screenshot

现在怎么办?在我看来,每次调试运行时再次从命令行启动 cscript.exe 非常麻烦。

有没有一种方法可以简单地使用 VS 调试脚本? 另外,对于其他调试工具的提示也将不胜感激。


编辑:
t0nyh0答案 a> 非常接近。我创建一个虚拟控制台应用程序,编译并出现调试器。然而,有两件事并不完美

  1. cscript.exe总是要求使用调试器(VS的哪个实例)。
    可以通过直接在命令行中指定某个调试器实例来解决这个问题吗?

  2. 为了触发构建后事件,必须对源进行一些修改。目前,我只需添加/删除一个空行即可触发我的虚拟项目的构建。
    有没有办法始终执行构建后脚本,即使没有任何更改?

I have a .js file that normally gets executed by cscript.exe (i.e. is not run in the browser and cannot be run there).

I know, that I can feed cscript.exe the //X parameter in order to get asked for a debugger to choose. Ok. That's fine.

I select "Visual Studio 2005 Debugger", IDE comes up, execution stops on the first line. Fine.

Script terminates (or I terminate it), I edit something and want to debug it again.

Simple thought would be just to hit F5 and run the debugger again. But this doesn't work. VS just tells me that it couldn't find any debugging symbols in cscript.exe:
screenshot

What now? Starting cscript.exe from the command line again for each debug run is quite cumbersome in my opinion.

Is there a way to simply debug the script with VS? Also hints for other debugging tools would be appreciated.


Edit:
The answer of t0nyh0 is pretty close. I create a dummy console application, compile and the debugger comes up. However, two things are not perfect

  1. cscript.exe always asks for the debugger to use (which instance of VS).
    Could this be overcome by specifying a certain debugger instance directly in the command line?

  2. In order to fire a post-build event, there have to be some modifications in the sources. Currently, I simply add/delete a blank line to trigger building of my dummy project.
    Is there a way to always execute the post-build script, even if nothing has changed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

南街九尾狐 2025-01-13 08:57:38

可能无法将调试器附加到 cscript.exe 本身,但您可以创建一个构建后事件来运行批处理文件,该批处理文件执行 cscript.exe / /x myScript.js 命令,以便每次构建时,它都会自动为您执行。

有关构建后事件的更多信息,请参阅:http ://msdn.microsoft.com/en-us/library/ke5z92ks(v=vs.80).aspx

There might not be a way to attach the debugger to cscript.exe itself, but you may be able to create a post-build event that runs a batch file that executes the cscript.exe //x myScript.js command so that every time you build, it executes for you automatically.

See this for more information on post-build events: http://msdn.microsoft.com/en-us/library/ke5z92ks(v=vs.80).aspx

如梦 2025-01-13 08:57:38

虽然不是调试器工具,但您应该考虑使用 Visual Studio 的 JavaScript 测试框架,例如 Cutzpah,这很可能会让你的生活变得更轻松。

除了标准浏览器调试工具(Firebug 或 Chrome Inspector)之外,我发现这就是我通常需要构建干净、经过测试、几乎没有错误的 JavaScript 代码。

While not a debugger tool, you should consider using a JavaScript testing framework for Visual Studio, such as Chutzpah, which will most likely make your life a lot easier.

Along with standard browser debugging tools (Firebug or Chrome Inspector), I've found that's all I usually need to build clean, tested, mostly-bug-free JavaScript code.

土豪我们做朋友吧 2025-01-13 08:57:38

我手头没有cscript,但我想你可以尝试手动将VS附加到进程中。

使用 cscript.exe //x myScript.js 启动 js 后,单击“调试 - 附加到进程”,找到 cscript.exe 进程并附加到它。

我忘记VS2005有没有这个功能,但是VS2008和VS2010有。

它是 VS 进行调试的本机调试操作(附加到正在运行的进程)。如果这不起作用,我认为您无法使用 Visual Studio 来完成此操作。

I don't have cscript at hand, but I think you can try to attach VS to the process manually.

After you start up your js using cscript.exe //x myScript.js, click "Debug - Attach to Process", find your cscript.exe process and attach to it.

I forget if VS2005 has this function but VS2008 and VS2010 do.

It is the native debug action that VS takes to debug (attach to the running process). If this doesn't work, I don't think you can do this using Visual Studio.

最笨的告白 2025-01-13 08:57:38

Best Javascript Debugger is Rhino Debugger See http://www.mozilla.org/rhino/debugger.html .
it is open source and you can get the source code of the Debugger GUI.
you can customise it as you wish :-) .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文