我该如何只回显空白而不换行 [英] how do I echo only white space and no newline

查看:88
本文介绍了我该如何只回显空白而不换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个简单的批处理脚本,该脚本循环遍历目录中的文件并使用ffmpeg处理它们.出于可读性考虑,我想缩进ffmpeg输出4个空格,但是我无法提出一种可行的方法.

I'm working on a simple batch script that loops over files in a directory and process them with ffmpeg. for readability purposes, I want to indent the ffmpeg output 4 spaces, but I cannot come up with a way that works.

@echo off

for %%a in (%~dp0rawVideo\*.MP4) do (

    if exist %~dp0rawAudio\%%~na.wav (
        echo Already Processed :
        echo     %%a
    ) else (
        echo Processing :
        echo     %%a
        echo|set /p leadingSpace="#   "   
        ffmpeg -c:v h264 -threads 24 -i %%a -map_channel 0.1.0 -map_channel -1 -y -v quiet -stats %~dp0rawAudio\%%~na.wav
    )

    echo(
)
pause

如果我只是这样做,那么我什么也不会得到,因为我已经阅读了导致空白的窗口条.

If I just do this i get nothing, because I've read windows strips leading white spaces.

echo|set /p leadingSpace="    " 

我也尝试了退格技巧,但没有成功.没办法吗?

I tried what I think is the backspace trick as well, but it didn't work. Is there no way of doing this?

推荐答案

第一个解决方案

这是一种运行命令并为由前缀输出的每一行添加前缀的方法.

Here's a way to run your command and prefix each line outputted by a prefix.

不带参数的简单示例:

@echo off
for /F "delims=" %%a in ('ffmpeg.exe 2^>^&1') do echo #    %%a

问题:

#    ffmpeg version N-80980-g7af44ce Copyright (c) 2000-2016 the FFmpeg developers
#      built with gcc 5.4.0 (GCC)
#      configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-li
bmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --enable-fontconfig --enabl
e-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable
-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug -
-enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enab
le-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-li
bspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-l
ibvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --en
able-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
#      libavutil      55. 28.100 / 55. 28.100
#      libavcodec     57. 50.100 / 57. 50.100
#      libavformat    57. 41.100 / 57. 41.100
#      libavdevice    57.  0.102 / 57.  0.102
#      libavfilter     6. 47.100 /  6. 47.100
#      libswscale      4.  1.100 /  4.  1.100
#      libswresample   2.  1.100 /  2.  1.100
#      libpostproc    54.  0.100 / 54.  0.100
#    Hyper fast Audio and Video encoder
#    usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
#    Use -h to get full help or, even better, run 'man ffmpeg'

它将标准错误重定向到标准输出(因此错误消息也带有前缀),并使用空定界符,因此%%a是整行.

it redirects standard error to standard output (so error messages are also prefixed) and uses empty delimiter, so %%a is the full line.

由于每当发出一条线路时都会呼叫您,因此很容易以您想要的方式回显它.

Since you are called each time a line is issued, it is easy to echo it the way you want.

当然,如果命令仅发出一行,它也可以工作.

Of course it also works if the command issues just one line.

第二个解决方案

由于只有一行,所以一种替代方法是使用一个临时文件来获取ffmpeg的输出,然后以交互方式分配变量,并将此文件重定向为输入.然后根据需要回显它:

Since you only have one line, an alternative would be to use a temporary file to get the output of ffmpeg, then assign a variable interactively with this file redirected as input. Then echo it as you want:

ffmpeg -c:v h264 -threads 24 -i %%a -map_channel 0.1.0 -map_channel -1 -y -v quiet -stats %~dp0rawAudio\%%~na.wav> %TEMP%\tmpf
set /P ffmpegout=<%TEMP%\tmpf
echo     %ffmpegout%

这篇关于我该如何只回显空白而不换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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