如何使用POSIX执行命令并获取C ++中的命令输出?(How do I execute a command and get output of command within C++ using POSIX?)
当我从C ++程序中运行时,我正在寻找一种获取命令输出的方法。 我已经看过使用了system()函数,但这只会执行一个命令。 以下是我正在寻找的例子:
std::string result = system( "./some_command" ) ;
我需要运行一个任意命令并得到它的输出。 我看过Boost.org,但我没有找到任何能给我我需要的东西。
I am looking for a way to get the output of a command when it is run from within a C++ program. I have looked at using the system() function, but that will just execute a command. Here's an example of what I'm looking for:
std::string result = system("./some_command");
I need to run an arbitrary command and get its output. I've looked at Boost.org, but I have not found anything that will give me what I need.
原文:https://stackoverflow.com/questions/478898
最满意答案
看来罪魁祸首是执行IL编织的第三方库(Fody.PropertyChanged)。
如果我没有这个库创建一个新的WPF项目,我可以在Watch窗口中使用
Math.Sin()
。 一旦我安装PropertyChanged
,我开始得到“在这种情况下不可用”的错误。感谢@BACON带领我找到正确的道路。
以下是我在PropertyChanged网站上发布的问题的链接:
http://code.google.com/p/propertychanged/issues/detail?id=6&thanks=6&ts=1330494634
编辑
随后,事实证明这可能是Mono-Cecil中的一个错误,PropertyChanged使用这个错误:
It appears that the culprit is a third-party library that performs IL weaving (Fody.PropertyChanged).
If I create a new WPF project without this library, I'm able to use
Math.Sin()
in the Watch window. Once I installPropertyChanged
, I start getting the "not available in this context" error.Thanks to @BACON for leading me down the right path to figuring this out.
Here's a link to an issue I posted on the PropertyChanged site:
http://code.google.com/p/propertychanged/issues/detail?id=6&thanks=6&ts=1330494634
Edit
And subsequently, it turns out this is probably a bug in Mono-Cecil, which PropertyChanged uses:
相关问答
更多-
看来罪魁祸首是执行IL编织的第三方库(Fody.PropertyChanged)。 如果我没有这个库创建一个新的WPF项目,我可以在Watch窗口中使用Math.Sin() 。 一旦我安装PropertyChanged ,我开始得到“在这种情况下不可用”的错误。 感谢@BACON带领我找到正确的道路。 以下是我在PropertyChanged网站上发布的问题的链接: http://code.google.com/p/propertychanged/issues/detail?id=6&thanks=6&ts ...
-
你在这里看到的行为是一个错误。 在这种情况下,C#调试器不应显示静态成员。 我向代码库的当前所有者证实了这一点,他将为Visual Studio的下一个版本提交一个错误。 发生这种情况的具体方案是 Just My Code已启用 该类型定义为确定为非用户程序集的内容 引用和对象实例的类型不同(将hash2切换为SHA1Cnf ,问题消失) 请注意,可能会出现其他情况。 这是我在调试/实验中能够缩小范围的行为。 The behavior you are seeing here is a bug. The C# ...
-
Visual Studio将使用项目引用的程序集执行此操作。 使用其名称空间尚未包含但可通过引用的程序集使用的类型。 如果你鼠标悬停它,你会在符号的左下角有一个小弹出窗口。 这将让你自动拉入适当的使用。 我一直使用AssemblyInfo.cs的CLSCompliantAttribute来使用它b / c默认情况下System不可用。 当我发现需要为一些代码添加跟踪时,我也发现自己经常以这种方式引入System.Diagnostics 。 Visual Studio will do that with as ...
-
我发现了问题。 这是由于延伸“我在哪里”。 我的扩展程序可用于Visual Studio 2010.这不适用于VS 2012.我做了一个hack以便它可以安装在VS 2012上。这导致了这个问题。 我禁用了这个扩展,现在一切正常。 I found the problem. It was due to a extension "Where Am I". Where Am I extension is available for Visual Studio 2010. This is not available ...
-
请参阅使用DebuggerDisplay属性 如果您通过属性标记了类: [DebuggerDisplay("x = {X} y = {Y}")] public class MyClass { public int X { get; private set; } public int Y { get; private set; } } Watch窗口的Value列中显示的输出如下所示: x = 5 y = 18 See Using DebuggerDisplay Attribute If yo ...
-
在Visual Studio的Watch窗口中使用LINQ表达式(Using LINQ expressions in Visual Studio's Watch window)[2023-10-08]
我试图重现您的问题并找到以下内容: 监视窗口似乎使用您在代码中引用的命名空间(通过using )。 如果您不在代码文件中使用linq(和System.Linq命名空间),则监视窗口无法找到扩展名。 如果你有using System.Linq; 并在代码中使用该命名空间中的内容,监视窗口将查找并执行linq扩展。 (如果不使用System.Linq的任何System.Linq ,则会优化引用,因此在运行时不会加载此程序集,并且调试程序无法使用它)。 I tried to reproduce your prob ... -
在2012年及以后,答案是Debugger Type Visualizers。 有关2012版本以及详细信息(如果要实现自定义的详细信息), 请参阅Visual Studio团队博客,查看MSDN文档。 In 2012 and later, the answer is Debugger Type Visualizers. See the Visual Studio team blog for the 2012 version and for the nitty gritty details (if you ...
-
这是由于Fody。 我们停止使用Fody并解决了这个问题。 Super late reply, but as of sometime around the beginning of 2018 Fody no longer causes this problem. It was a Cecil issue and that was fixed with Cecil 0.10.
-
再试一次,没有连接到进程(而是点击F5),并确保勾选了“启用VIsual Studio托管进程”(右键单击项目 - >属性 - >调试)复选框。 关于为什么有时会出现这种情况的解释,有时候没有,以及为什么我提供的建议可能有所帮助,请参阅JaredPar关于该主题的博客文章。 Like many bugs, it disappeared and I have no idea why. :(
-
在观察窗口中搜索值(searching a value in watch window)[2023-05-11]
我担心在VS2010观察窗口中没有这种内置的搜索功能(尽管观察窗口有很多很酷的功能 )。 另请参阅此未解决的问题: 在visual studio中的Object watch窗口中搜索文本 然而,有一些商业扩展提供了这种功能。 例如:摘自OzCode VS扩展功能列表: 搜索 调试对象和集合时,通常会查找特定属性或字段,或者属性或字段中保存的值。 不幸的是,这通常涉及大量点击和滚动,或编写自定义调试特定代码。 即使在简单的结构中查找项目也不容易,更不用说在复杂的对象图中这样做了。 通过我们的“搜索”功能,情况 ...