我想管道标准输出的程序,同时保持它在屏幕上。

通过一个简单的例子(这里使用echo只是为了说明):

$ echo 'ee' | foo ee <-我想看到的输出

我知道tee可以复制stdout到文件,但这不是我想要的。 $ echo 'ee' | tee output.txt | foo

我试着 $ echo 'ee' | tee /dev/stdout | foo但它不起作用,因为tee输出到/dev/stdout是通过管道输出到foo的

我对这三个文件的用途感到相当困惑。如果我的理解是正确的,stdin是程序写入它的请求以在进程中运行任务的文件,stdout是内核写入它的输出和它访问的请求进程的信息的文件,stderr是所有异常都输入的文件。在打开这些文件来检查这些是否真的发生了,我发现似乎没有什么建议!

我想知道的是这些文件的确切目的是什么,绝对愚蠢的答案与很少的技术术语!

这是我的控制器:

<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class RegisterController extends Controller
{
    public function register(Request $request)
    {
        dd('aa');
    }
}

如截图所示,类存在并且在正确的位置:

我的api.php路由:

Route::get('register', 'Api\RegisterController@register');

当我使用Postman命中我的寄存器路径时,它给了我以下错误:

目标类[Api\RegisterController]不存在。

我该怎么解决呢?


多亏了这些答案,我才得以修复它。我决定对这个路由使用完全限定类名,但是答案中描述了其他选项。

Route::get('register', 'App\Http\Controllers\Api\RegisterController@register');

我正在运行一个bash脚本,该脚本为执行该命令创建一个日志文件

我使用以下方法

Command1 >> log_file
Command2 >> log_file

这只发送标准输出,而不发送出现在终端上的标准错误。

当输送Python程序的输出时,Python解释器会混淆编码并将其设置为None。这意味着这样一个程序:

# -*- coding: utf-8 -*-
print u"åäö"

正常运行时工作正常,但失败:

unicode编码错误:'ascii'编解码器无法编码字符u'\xa0'在位置0:序数不在范围(128)

在管道序列中使用时。

什么是最好的方法使这工作时管道?我能告诉它使用shell/文件系统/任何正在使用的编码吗?

到目前为止,我看到的建议是直接修改你的site.py,或者使用以下方法硬编码defaultencoding:

# -*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
print u"åäö"

有没有更好的方法让管道工作?

是否有一种容器适配器可以反转迭代器的方向,以便我可以使用基于范围的for-loop反向迭代容器?

使用显式迭代器,我将转换如下:

for (auto i = c.begin(); i != c.end(); ++i) { ...

到这个:

for (auto i = c.rbegin(); i != c.rend(); ++i) { ...

我想把它转换成:

for (auto& i: c) { ...

:

for (auto& i: std::magic_reverse_adapter(c)) { ...

有这样的东西吗,还是我必须自己写?

如何在Python中将标准输出重定向到任意文件?

When a long-running Python script (e.g, web application) is started from within the ssh session and backgounded, and the ssh session is closed, the application will raise IOError and fail the moment it tries to write to stdout. I needed to find a way to make the application and modules output to a file rather than stdout to prevent failure due to IOError. Currently, I employ nohup to redirect output to a file, and that gets the job done, but I was wondering if there was a way to do it without using nohup, out of curiosity.

我已经试过了。Stdout = open('somefile', 'w'),但这似乎并没有阻止一些外部模块仍然输出到终端(或者sys. exe)。Stdout =…Line根本没有开火)。我知道它应该在我测试过的更简单的脚本上工作,但我还没有时间在web应用程序上进行测试。

如何在Windows命令提示符中运行命令行应用程序,同时显示输出并将输出重定向到文件?

例如,如果我要运行命令dir > test.txt,这将把输出重定向到一个名为test.txt的文件,而不显示结果。

我如何写一个命令来显示输出并将输出重定向到Windows命令提示符中的文件,类似于Unix上的tee命令?

是否存在sys.stdout.write()比print更可取的情况?

(例子:更好的性能;更有意义的代码)

我注意到,在许多模板引擎中,在HTML5 Boilerplate中,在各种框架中,在纯php站点中,都有no-js类添加到<HTML>标记中。

为什么要这么做?是否有某种默认的浏览器行为对这个类做出反应?为什么总是包括它?如果没有no-“no-js”情况和html可以直接寻址,这不会使类本身过时吗?

下面是一个来自HTML5 Boilerplate index.html的例子:

<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]>    <html lang="en" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]>    <html lang="en" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]>    <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->

如您所见,<html>元素总是有这个类。 有人能解释一下为什么这种情况如此频繁吗?