/usr/bin/flock -n /mnt/d/Torrents/Temp/media.lockfile bash -c 'source /mnt/c/Users/MissAnastasiia/Script/Media.sh; prepare "$Downloads"'
wsl /mnt/c/Users/MissAnastasiia/Script/start.sh
echo "Добавляем новый сериал"
newserial=$(mv -fv "$FOLDER" "$SerialsFolder"/) && echo -e ${Green}"Добавление прошло успешно"${NC} && sleep 5s && prepare "$Downloads"
echo_stdout_stderr_test.cmd
@echo OFF
echo output message 1
1>&2 echo error message 1
echo output message 2
1>&2 echo error message 2
exit /b 0
read_callee_stdout_stderr.ps1
# based on: https://stackoverflow.com/questions/24222088/capture-program-stdout-and-stderr-to-separate-variables
$script = 'echo_stdout_stderr_test.cmd'
$type = [System.Management.Automation.ErrorRecord]
$combined = invoke-expression -command ('{0}\{1} 2>&1' -f (resolve-path '.'), $script )
$child_stderr = $combined | where-object { $_ -is $type }
$child_stdout = $combined | where-object { $_ -isnot $type }
write-output ('child process output: {1}{0}' -f ( $child_stdout -join [char]10 ), [char] 10 )
write-output ('child process error: {1}{0}' -f ( $child_stderr -join [char]10 ), [char] 10 )
.\read_callee_stdout_stderr.ps1
child process output:
output message 1
output message 2
child process error:
error message 1
error message 2
STDERR
в баш тоже используется 1>&2 echo
5 B C A B 0 = > 2 ; 5 = = K E 4 8 A B @ 8 1 C B 8 2 > 2 ? > 4 A 8 A B 5 < K W i n d o w s 4 ; O L i n u x . 8 A B @ 8 1 C B 8 2 K < > 6 = > C A B 0 = > 2 8 B L 8 7 M i c r o s o f t S t o r e : h t t p s : / / a k a . m s / w s l s t o r e
Теперь wsl есть ещё и в msstore ....
Select-String -Notmatch 'M i c r o s o f t S t o r e'
в баш тоже используется 1>&2 echo
PS C:\> echo aaa 1>&2
строка:1 знак:10
+ echo aaa 1>&2
+ ~~~~
Оператор "1>&2" зарезервирован для использования в будущем.
но со стороны повершелла код будет устроен так же
$env:PATH="${env:PATH};C:\Program Files\Git\bin"
$command = 'bash.exe echo_stdout_stderr_test.sh 2>&1'
.\read_callee_stdout_stderr.ps1
child process output:
output message 1 output message 2
child process error:
error message 1 error message 2
wsl /mnt/c/Users/MissAnastasiia/Script/start.sh
-> '/mnt/d/Serials/Falshivyj.flag.S01.2019'
(wsl /mnt/c/Users/MissAnastasiia/Script/start.sh) | -replace ‘.*Downloads (.*)', '-> $1’
renamed '/mnt/d/Downloads/Falshivyj.flag.S01.2019.WEB-DL.1080p/Falshivyj.flag.S01.E08.2019.WEB-DL.1080p.mkv' -> '/mnt/d/Downloads/Falshivyj.flag.S01.2019.WEB-DL.1080p/Falshivyj.flag.S01.E08.2019.mkv' renamed '/mnt/d/Downloads/Falshivyj.flag.S01.2019.WEB-DL.1080p/Falshivyj.flag.S01.E07.2019.WEB-DL.1080p.mkv' -> '/mnt/d/Downloads/Falshivyj.flag.S01.2019.WEB-DL.1080p/Falshivyj.flag.S01.E07.2019.mkv' renamed '/mnt/d/Downloads/Falshivyj.flag.S01.2019.WEB-DL.1080p/Falshivyj.flag.S01.E06.2019.WEB-DL.1080p.mkv' -> '/mnt/d/Downloads/Falshivyj.flag.S01.2019.WEB-DL.1080p/Falshivyj.flag.S01.E06.2019.mkv' renamed '/mnt/d/Downloads/Falshivyj.flag.S01.2019.WEB-DL.1080p/Falshivyj.flag.S01.E05.2019.WEB-DL.1080p.mkv' -> '/mnt/d/Downloads/Falshivyj.flag.S01.2019.WEB-DL.1080p/Falshivyj.flag.S01.E05.2019.mkv' renamed '/mnt/d/Downloads/Falshivyj.flag.S01.2019.WEB-DL.1080p/Falshivyj.flag.S01.E04.2019.WEB-DL.1080p.mkv' -> '/mnt/d/Downloads/Falshivyj.flag.S01.2019.WEB-DL.1080p/Falshivyj.flag.S01.E04.2019.mkv' renamed '/mnt/d/Downloads/Falshivyj.flag.S01.2019.WEB-DL.1080p/Falshivyj.flag.S01.E03.2019.WEB-DL.1080p.mkv' -> '/mnt/d/Downloads/Falshivyj.flag.S01.2019.WEB-DL.1080p/Falshivyj.flag.S01.E03.2019.mkv' renamed '/mnt/d/Downloads/Falshivyj.flag.S01.2019.WEB-DL.1080p/Falshivyj.flag.S01.E02.2019.WEB-DL.1080p.mkv' -> '/mnt/d/Downloads/Falshivyj.flag.S01.2019.WEB-DL.1080p/Falshivyj.flag.S01.E02.2019.mkv' renamed '/mnt/d/Downloads/Falshivyj.flag.S01.2019.WEB-DL.1080p/Falshivyj.flag.S01.E01.2019.WEB-DL.1080p.mkv' -> '/mnt/d/Downloads/Falshivyj.flag.S01.2019.WEB-DL.1080p/Falshivyj.flag.S01.E01.2019.mkv' renamed '/mnt/d/Downloads/Falshivyj.flag.S01.2019.WEB-DL.1080p' -> '/mnt/d/Downloads/Falshivyj.flag.S01.2019' renamed '/mnt/d/Downloads/Falshivyj.flag.S01.2019' -> '/mnt/d/Serials/Falshivyj.flag.S01.2019'
(wsl /mnt/c/Users/MissAnastasiia/Script/start.sh) -replace ‘.*Downloads (.*)', '-> $1’
, без "трубы"....
echo "Output: some info to output"
...
echo 'some info, that shoud NOT be visible outside'
....
echo "Output: some other info to output"
....
...
(wsl 'run.sh' | select-string 'Output:') -replace '^Output:'
...
function prepare(){
for value in "${@}"
do
find "$@" -not -iname "*!qB" -o -not -iname "*!ut" | sort -r | while read file; do RENAME=$(dirname "$file")/$(echo $(basename "$file") | sed -f "$Template" );
if [[ "$file" != "$RENAME" ]];
then
mv -fv "$file" "$RENAME" && sleep 0.1s || exit_stop 0
fi
Massive_file=`echo ${file[@]} ${RENAME[@]} | tr ' ' '\n' | sort | uniq -u`
done
done
if [[ "$file" == "$RENAME" ]] && [[ "$Massive_file" == "" ]];
then
find_file "${@}"
fi
}
function find_file(){
for value in "${@}"
do
x="$IFS";IFS=$'\n';for File in $(find "$@" -regex "$ExVideo" -o -regex "$ExMusic" | sort -u );
do
IFS="$x"
if [[ -n "${File[@]}" ]];
then get_names "${File[@]}"
fi
done
done
}
function rename(){
for value in "${@}"
do
if [[ -n "$@" ]];
then
NEWNAME=$( echo "${@}" | sed -f "$Template" )
mv -fv "${@}" "$NEWNAME"
fi
done
}
function get_names(){
for value in "${@}"
do
WhatFolder_all_address=$(dirname "${@}" );
RootFolder=$(dirname "$WhatFolder_all_address" | sed s'/\/\/[^/]//'g );
WhatFolder=$(dirname "${@}" );
FileName=$(basename "${@}" );
Extension=${FileName##*.};
FOLDER=$(echo "$Downloads")/$(echo "${@}" | cut -d '/' -f 5 ) ;
ARTIST_FOLDER=$(echo "${@}" | cut -d '/' -f 5 ) ;
done
if [[ -n "$WhatFolder_all_address" ]] && [[ -n "$RootFolder" ]] && [[ -n "$WhatFolder" ]] && [[ -n "$FileName" ]] && [[ -n "$Extension" ]] && [[ -n "$FOLDER" ]];
then
type_media "${@}"
fi
}
function type_media(){
for value in "${@}"
do
# немножко цвета
Red='\e[1;31m'
Green='\e[1;32m'
Blue='\e[1;34m'
Black='\e[0;30m'
DarkGray='\e[1;30m'
Light_Red='\e[1;31m'
Light_Green='\e[1;32m'
Brown_Orange='\e[0;33m'
Yellow='\e[1;33m'
Light_Blue='\e[1;34m'
Purple='\e[0;35m'
Light_Purple='\e[1;35m'
Cyan='\e[0;36m'
Light_Cyan='\e[1;36m'
Light_Gray='\e[0;37m'
White='\e[1;37m'
# отмена цвета
NC='\e[0m'
#echo -e ${Brown_Orange}"type_media"${NC}
if [[ -n "$Extension" ]];
then
if [[ "$ExVideo" =~ "$Extension" ]];
then
#echo -e "Обнаружены ${Cyan}VIDEO${NC} файлы."
#echo "${file[@]}"
sort_video "${@}"
fi
if [[ "$ExMusic" =~ "$Extension" ]];
then
#echo -e "Обнаружены ${Yellow}LOSSLESS${NC} файлы."
#echo "${file[@]}"
sort_music "${@}"
fi
fi
done
}
function convert_video(){
# convert video
for value in "${@}"
do ffmpeg -y -i "$@" -sn "${@%.*}.mkv" ; rm -rf "$@" || rm -rf "${@%.*}.mkv"; done
}
function convert_music(){
#echo -e ${Light_Cyan}"Начинаю конвертацию FLAC"${NC}
for value in "${@}"
do
#convert music
#echo -e "Обнаружены ${Yellow}CUE${NC} файлы."
#echo -e "Convert ${Yellow}FLAC ${NC}файлов."
# перекодирует CUE файл в UTF8 cp1251
dos2unix "$CUEFILE"
enconv -L russian -x utf8 "$CUEFILE" && echo "success $?" || enconv -c -x utf8 "$CUEFILE"
# получаем жанр и год из CUE файла.
function parsecue(){
GENRE=$(head -n 6 "$CUEFILE" | grep -i GENRE | sed "s/REM GENRE //i" )
DATE=$(head -n 6 "$CUEFILE" | grep -i "DATE" | sed "s/REM DATE //i" )
}
# распилим его на отдельные FLAC части
cuebreakpoints "$CUEFILE" | shnsplit -o flac -d "$TempMusic" "$File"
# проставим тэги из CUE в новые FLAC части.
cuetag "$CUEFILE" "$TempMusic"/split-track*.flac ;
# напарсим не хватающих тэгов жанра и года выпуска из CUE файла.
parsecue
# впишем тэги и приведём имена файлов нарезанных частей в человеческий вид
for SLICE in "$TempMusic"/split-track*.flac;
do
metaflac --set-tag "GENRE=$GENRE" --set-tag "DATE=$DATE" "$SLICE"
ARTIST=$(metaflac "$SLICE" --show-tag=ARTIST | sed s/.*=//g)
TITLE=$(metaflac "$SLICE" --show-tag=TITLE | sed s/.*=//g)
TRACKNUMBER=$(metaflac "$SLICE" --show-tag=TRACKNUMBER | sed s/.*=//g)
TRACKNAME=$(echo "$TRACKNUMBER - $TITLE.flac" | sed -f "$Template")
mv -fv "$SLICE" "$TempMusic"/"$TRACKNAME"
done
sleep 0.5s
clean "$WhatFolder_all_address"/*
sleep 2s
mv "$TempMusic"/* "$WhatFolder_all_address"/
#exit_stop 0
done
}
$result = wsl ls