C# 程序可以在 cmd 提示符下运行,但不能单独运行?

发布于 2024-07-30 01:05:11 字数 496 浏览 1 评论 0原文

我会发布一个片段,但老实说,我不知道我的代码的哪一部分可能会执行此操作。 程序很大,我不想让你们都费力地看完它。 什么样的事情可能是造成这种情况的原因? 从命令提示符调用时一切正常:“readoo.exe”。 但是当我单击其文件中的 exe 时。 。 。 “readoo.exe遇到问题,需要关闭......”

这最终将成为一项计划任务 -> 我很担心,这有用吗?

我从来没有调试过,我只用过记事本。 我正在学习,感觉这增强了我对项目的理解。

它几乎立即崩溃。 尽管文件路径是相对的,但没有快捷方式。

尝试这个方法:快捷方式-> 属性-> 快捷方式-> 开始于。 我没有“快捷方式”选项,

我的程序读取日志文件、解析并根据找到的内容创建 4 个新文件

Microsoft 错误报告显示未找到文件。 但这怎么可能呢? 文件就在那里,尽管是相对的。

I would post a snippet, but I honestly have no idea what part of my code could possibly be doing this. The program is sizable, I don't want to make you all wade through it. What kinds of things could possibly be the cause of this? Everything works perfectly when called from the command prompt: "readoo.exe". But when I click the exe in its file. . . "readoo.exe has encountered a problem and needs to close. . ."

this is intended to eventually be a scheduled task -> i'm worried, will it work?

i've never debugged, all i've ever used is notepad. I am learning, and feel that this strengthens my understanding of a project.

it crashes nearly immediately. there are no shortcuts, though the file paths are relative.

trying this method: shortcut -> properties -> shortcut -> Start In. I don't have a "shortcut" option

my program reads log files, parses, and creates 4 new files based on the found content

Microsoft Error Report says file not found. But how can this be? the files are there, albeit relative.

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

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

发布评论

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

评论(7

泼猴你往哪里跑 2024-08-06 01:05:11

在代码周围放置一个 try/catch 并将异常消息输出到 catch 块中的控制台。 这应该会给你一些线索。

Put a try/catch around your code and output the exception message to the console in the catch block. That should give you some clues.

梦开始←不甜 2024-08-06 01:05:11

如果您的应用程序依赖于某个应与该 exe 位于同一路径上的文件,则可能会发生这种情况。

您必须将 exe(或 exe 的快捷方式)的属性更改为“开始于”exe 所在的目录。 对于快捷方式,右键单击快捷方式 -> 属性-> 快捷方式-> 开始于。

我想这就是我认为可能的原因。

编辑:在代码末尾添加 Console.ReadLine 以使其暂停,以便您查看抛出的任何异常。 当您使用 Windows 资源管理器运行它时,这应该会有所帮助。

If your application relies on some file that should be on the same path of that exe, that can occurr.

You will have to change the properties of the exe (or shortcut to the exe) to "Start In" the directory where your exe is. For a shortcut, right click on the shortcut -> properties -> shortcut -> Start In.

I guess that is what I think could be the cause.

EDIT: Add a Console.ReadLine towards the end of your code to make it pause for you to see any exception thrown. That should help when you run it using windows explorer.

执手闯天涯 2024-08-06 01:05:11

可能有两件事:

  • 当您单击程序或从命令提示符运行时,当前目录可能不同。
  • 当您单击正在使用标准命令提示符的程序时,设置和路径可能会有所不同,或者当您从提示符运行程序时打开 Visual Studio 命令提示符。

There are 2 things that it could be:

  • The current directory could be different when you click on the program or run from the command prompt.
  • The settings and path could be different when you click on the programe you are using the standard command prompt, are you opening the visual studio command prompt when you run the program from the prompt.
哭泣的笑容 2024-08-06 01:05:11

我首先要确定这两种执行方法的不同之处。 有修改任何东西的快捷方式吗?

  • 起始目录?
  • 执行账户?
  • 命令行参数?

I would start with identifying what is different in the two methods of execution. Is there a shortcut modifying anything?

  • The starting directory?
  • The execution account?
  • command line arguments?
得不到的就毁灭 2024-08-06 01:05:11

尝试将 System.Diagnostics.Debugger.Break() 调用作为 Main() 中的第一件事,系统会要求您附加调试器 - 这肯定会显示你这两次调用之间有什么不同。

Try putting a System.Diagnostics.Debugger.Break()call as the first thing in Main() and you'll be asked to attach a debugger - this should definitely show you what is different betweent the 2 invocations.

尝蛊 2024-08-06 01:05:11

这可能是在寻找无法找到的 dll,或者正在寻找与所需版本不同的版本。

您可以尝试使用 sysinternals 中的 Process Monitor 或 Process Explorer 来查看它在工作时加载的 dll 以及在何处找到它们。

This is probably looking for a dll that it can't find or is finding a different version from what it wants.

You could try Process Monitor or Process Explorer from sysinternals to see what dlls it loads when it does work and where it finds them.

煮酒 2024-08-06 01:05:11

复制您的项目,然后开始对其进行修改。 当它不再崩溃时,您就已经删除了导致问题的部分。

当您双击它时,什么时候会失败? 立即,还是仅当您采取某种行动时?

您还可以向其中添加大量日志记录,这也可以表明问题出在哪里。

Take a copy of your project, and then start hacking bits out of it. When it no longer crashes, you've removed the bit causing the problem.

At what point does it fail when you double-click on it? Immediately, or only when you take a certain action?

You could also add a lot of logging to it, which could indicate where the problem is too.

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