PSQL:如何阻止命令行上的任何输出? [英] PSQL: How can I prevent any output on the command line?

查看:395
本文介绍了PSQL:如何阻止命令行上的任何输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题:作为TFS生成过程的一部分,我试图通过批处理文件在命令行中运行数据库生成脚本,以便对已知数据集进行夜间测试。

My problem: I'm trying to run a database generation script at the command line via a batch file as part of a TFS build process to enable nightly testing on a known dataset.

我们运行的脚本在命令行上输出通知,警告和一些错误。我想至少抑制通知和警告,并尽可能消除错误,因为它们似乎对脚本的整体成功没有影响。就TFS构建过程而言,此输出似乎正在影响该过程的成功或失败。

The scripts we run are outputting Notices, Warnings and some Errors on the command line. I would like to suppress at least the Notices and Warnings, and if possible the Errors as they don't seem to have an impact on the overall success of the scripts. This output seems to be affecting the success or failure of the process as far as the TFS build process is concerned. It's highlighting every line of output from the scripts as errors and failing the build.

由于我们的系统在Windows上运行,因此我在网上找到的大多数潜在解决方案都不会出现。

As our systems are running on Windows, most of the potential solutions I've found online don't work as they seem to target Linux.

我已将 client_min_messages 更改为postgresql.conf文件中的错误,但是在查找时在与pgAdmin相同的配置下(工具>服务器配置),该值显示为Error,而当前值显示为Notice。

I've changed the client_min_messages to error in the postgresql.conf file, but when looking at the same configuration from pgAdmin (tools > server configuration) it shows the value as Error but the current value as Notice.

批处理文件中所有调用的行psql也使用 -q 标志,但这似乎只能阻止诸如CREATE TABLE和ALTER TABLE等基础知识。

All of the lines in the batch file that call psql use the -q flag as well but that only seems to prevent the basics such as CREATE TABLE and ALTER TABLE etc.

示例行批处理文件中的内容是:

An example line from the batch file is:

psql -d数据库-q< C:\Database\scripts\script.sql

psql -d database -q < C:\Database\scripts\script.sql

此命令的示例输出行:

警告:身份列的类型为未知
详细信息:仍然要进行关系创建。

WARNING: column "identity" has type "unknown" DETAIL: Proceeding with relation creation anyway.

-f 指定文件strong>标志没什么区别。

Specifying the file with the -f flag makes no difference.

我可以在开发机器上手动运行批处理文件,无论命令提示符上显示什么错误或消息,它都可以生成预期的数据库

I can manually run the batch file on my development machine and it produces the expected database regardless of what errors or messages show on the command prompt.

所以最终,我需要批处理文件中的所有psql命令才能静默运行。

So ultimately I need all psql commands in my batch files to run silently.

推荐答案

psql COMMAND &> output.txt

或者,使用您的示例命令:

Or, using your example command:

psql -d database -q < C:\Database\scripts\script.sql &> output.txt

这篇关于PSQL:如何阻止命令行上的任何输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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