windows - Windows 上的 fd/2 等价物是什么?
问题描述
例如,在 Linux 上,可以在 awk 脚本中将 stderr 称为 fd/2。示例:
if(system("test -e " myfile) != 0) myfile = "fd/2"
我需要在 Windows 上也可以使用的东西 - 请问myfile = fd/2
那里有什么?我似乎已经发现我可以exist
用来检查文件是否存在。谢谢你。
解决方案
D:\TEMP>type error.txt
The system cannot find the file specified.
D:\TEMP>dir nonexistingfile.txt 2>error.txt
Volume in drive D is HDD
Volume Serial Number is D46B-804B
Directory of D:\TEMP
D:\TEMP>type error.txt
File Not Found
D:\TEMP>
见微软文档
编辑:根据文档,@Raymond 链接,我已经看到 ist 可以在 Windows 下重定向错误。
D:\TEMP>del error
D:\TEMP>echo hallo | gawk "{ print \"Serious error detected!\" > \"/dev/stderr\"; print $0 }" 2>error
hallo
D:\TEMP>type error
Serious error detected!
或者,更有条件:
D:\TEMP>del error
D:\TEMP>gawk "BEGIN{ for (i=1; i<=4; i++) { if (i%2==0) { myfile=\"/dev/stderr\" } else { myfile=\"/dev/stdout\" }; print i >myfile }}" 2>error
1
3
D:\TEMP>type error
2
4
D:\TEMP>
推荐阅读
- r - 如何根据范围内的条件进行过滤?
- node.js - findAll 与模型返回奇数值续集
- javascript - Javascript 和正则表达式调整 - 条带化字符串
- python - 如何将 json 文件导入 Blender?
- python - 用数组填充的 Pandas 列,连接数组内的值
- macos - 如何在 Mac OSX 上对 PyInstaller + PyQt 应用程序进行代码设计,避免在应用程序公证后出现“二进制未签名”错误?
- revit-api - 如果我在 BIM 360 更新我的 Revit 模型,我会丢失以前注册的问题吗?
- amazon-web-services - 仅允许从 S3 存储桶的特定文件夹中删除的 IAM 策略
- amazon-web-services - 为什么当我选择 USER_SRP_AUTH 作为身份验证流类型时,AWS Amplify 会尝试使用 CUSTOM_AUTH 进行身份验证?
- python - 如何在列长度检查中忽略 NaN