NSIS close process by glob - process

I have a code for nsis which show you a message if specified process is run
nsProcess::_FindProcess "NCover.exe"
Pop $0
${If} $0 = 0
ifSilent +1 +3
SetErrorLevel 3
Abort
MessageBox MB_OK "Process NCover is running please close."
Goto Recheck
${EndIf}
But it's not work with a glob pattern like "*.res". What can i use to do this with glob?

Related

NSIS switch with multi-criteria case

May I do in NSIS switch with multi-criteria case like in JavaScript?
${Switch} $0
${Case} 2
DetailPrint "Connection to server failed: $0"
Abort
${Break}
${Case} 1
${Case} 3
${Case} "timeout"
DetailPrint "Database creating failed: $0"
Abort
${Break}
${EndSwitch}

Is there any if statment in awk to compare a word greped from a file?

I am new to any programming and shell scripting.
I am trying to make a if condition in shell script.
I am used of some computed codes for density functional theory (say Quantum espresso).
I want to make the program automatic via a shell script.
My code produce case.data which contains at the end stop (at $2 or we can say at second column).
For example below script should print stop
cat case.data | tail -n 1 | awk '{print $2}'
so if I get stop from above script then then if statement should not produce anything and the rest file should be executed. If I do not get stop from then above script then executable commands in my file should not be executed and a text file containing exit should be executed so that it terminates my job.
What I tried is:
#!bin/bash
# Here I have my other commands that will give us case.data and below is my if statement.
STOP=$(cat $case.dayfile | tail -n 1 | awk '{print $2}')
if [$STOP =="stop"]
then
echo "nil"
else
echo "exit" > exit
chmod u+x exit
./exit
fi
# here after I have other executable that will be executed depending on above if statement
Your whole script should be changed to just this assuming you really do want to print "nil" in the success case for some reason:
awk '{val=$2} END{if (val=="stop") print "nil"; else exit 1}' "${case}.data" || exit
and this otherwise:
awk '{val=$2} END{exit (val=="stop" ? 0 : 1)}' "${case}.data" || exit
I used a ternary in that last script instead of just exit (val!="stop") or similar for clarity given the opposite values of true in a condition and success in an exit status.
Like this?:
if awk 'END{if($2!="stop")exit 1}' case.data
then
echo execute commands here
fi

get exit code of a background process that completed a while ago

This may not be a completely new topic but I ran into a little bit odd situation.
I'm processing about 1000 files in a loop by kicking off a script in background. I want to take some actions on the files based on the exit code each process returns. By the time I go in a loop to wait for each process to complete I found that some of the process were already done. I modified the script to wait only if pgrep finds a process and just assumed a process completed successfully otherwise. The problem is- I have to know exit code of each process in order to take action on the corresponding file. Any ideas?
pid_list=()
for FILE in $SOME_FOLDER
do
(process with FILE as parameter) &
done
for pid in "${pid_list[#]}"
do
if pgrep $pid; then #process could have just completed as we got here
if wait $pid; then
echo "process $pid successfully completed!" >> $logfile
else
echo "process $pid failed!" >> $logfile
fnc_error_exit
fi
else
echo "assumed that process $pid successfully completed but I DON'T KNOW THE EXIT CODE!" >> $logfile
continue
fi
done
I cannot solve your problem exactly.
Since I do not know the exact situation of you, anyway, could you try another method using parent and child scripts ?
For example, the topmost script is like this:
for FILE in $HOME/*.txt
do
parent.sh $FILE &
done
Then, the parent.sh is like this:
child.sh $1
RC=$?
case $RC in
0 ) echo Exit code 0 for $1 >> parent.log
;;
1 ) echo Exit code 1 for $1 >> parent.log
;;
* ) echo Other Exit code $RC for $1 >> parent.log
;;
esac
The child script is like this:
grep -q hello $1
Then, the parent.sh will handle every exit code of the child.sh
All files will be handled by a parent.sh, without a missing handling.

NSIS Find files in silent mode not working

I have the following function to recursively search for dll files.
Function ProcessDLLFiles
Exch $0
Push $1
Push $2
FindFirst $1 $2 "$INSTDIR\*.dll"
loop:
IfErrors end
DetailPrint 'Found "$0\$2"'
FindNext $1 $2
goto loop
end:
FindClose $1
FindFirst $1 $2 "$0\*.*"
dirloop:
IfErrors dirend
IfFileExists "$0\$2\*.*" 0 dirnext
StrCmp $2 "." dirnext
StrCmp $2 ".." dirnext
Push "$0\$2"
call ${__FUNCTION__}
dirnext:
FindNext $1 $2
goto dirloop
dirend:
FindClose $1
Pop $2
Pop $1
Pop $0
FunctionEnd
When I run the installer normally, it works as expected and finds all dll files in the associated folder.
However, it does not find these files in silent mode, even though I can navigate to the directory it is searching in and see that the files are there. I already request admin privileges during installation, and Administrators have full permissions on the dll files in the folder.
Any ideas why it may not be finding the files?
When calling the nxs plugin to create a banner, needed to use /end parameter.

NSIS: Problem to copy 1 file to another excluding a line

I want to replace the file 1.txt with its original contents except the line in R1, for which I wrote the following code:
FileOpen $0 "1.txt" "r"
GetTempFileName $R0
FileOpen $1 $R0 "w"
loop:
FileRead $0 $2
IfErrors done
strcmp $R1 $2 loop here
here:
FileWrite $1 $2
Goto loop
done:
FileClose $0
FileClose $1
Delete "1.txt"
CopyFiles /SILENT $R0 "1.txt"
Delete $R0
But its not working properly, it keeps 1.txt as it is. Can somebody please help me to find out where is the problem?
I have just ran into the same problem. Fixed it by inserting a
ClearErrors
command before "loop:"