Test integrity of archive with 7-Zip in PowerShell
I am trying to test integrity of ZIP file
It looks like this command is working but I got many details about the file. I want to get a result if the test passed or failed in order to move to the next step.
Any idea how to do it? Something like:
$TestZip = 7z t \\bandit\global\QA\AgileTeam\bandit\Builds\8.6.22.607\8.6.22.607.10.zip
if ($TestZip)
{The test passed}
else
{Test failed}
The output is:
Path = \\bandit\global\QA\AgileTeam\bandit\Builds\8.6.22.607\8.6.22.607.10.zip
Type = zip
Physical Size = 5738248794
64-bit = +
Characteristics = Zip64
Everything is Ok
Files: 902
Size: 5927324719
Compressed: 5738248794
Tried this:
$TestZip = 7z t \\bandit\global\QA\AgileTeam\bandit\Builds\8.6.22.607\8.6.22.607.10.zip | set out
$ok = $out -like '*Everything is Ok*'
if ($ok) {write-host "Integrity test for Zip file passed"}
1 answer
-
answered 2022-05-04 11:01
phuclv
Errors are reported via exit code so just check it. No need to parse the output, you can just redirect the output to null. The way to check exit status in PowerShell is
$?
and$LASTEXITCODE
7z t $zip_file_path 2>$null 1>$null if ($?) { echo "Success" } else { echo "Failed" }
Update:
Use
if ($LASTEXITCODE -eq 0)
instead ofif ($?)
when stderr is redirected in older PowerShell (7.1.x and older) for more reliable result
$?
Contains the execution status of the last command. It contains True if the last command succeeded and False if it failed.
$LastExitCode
Contains the exit code of the last native program that was run.
do you know?
how many words do you know
See also questions close to this topic
-
How to require a dll inside .psd1 for a .psm1 that is being invoked from a .ps1?
I read a lot of the answers here and I can't seem to find what I am looking for. So please bear with me.
Each psm1 is a class.
I have:
Main.ps1
Modules/module01.psm1
Modules/module02.psm1
DLL/dllInQuestion.dll
I am trying to load a dll to use inside module02.psm1. I know that in order to do so I have to require it inside a .psd1. I created a psd1 for module02 and put it in the same folder and imported it like this "Import-Module" before the code but it didn't work.
I also tried to create a psd1 for Main.ps1 but it didn't work.
Can I require (using using module statements and Add-Type) all modules and dll inside a .ps1 script and require it inside a .psd1 for Main.ps1?
Thank you.
-
Subprocess $Env:Path python: The filename, directory name, or volume label syntax is incorrect
I am trying to change the windows environment variables, but I am having trouble doing so.
Before I tried to use
os.environ()
I tried out using powershell commands and adding a string to$Env:Path
which worked, but removing it with:$env:Path = ($env:Path.Split(';') | Where-Object -FilterScript {$_ -ne $Remove}) -join ';'
however didn't seem to remove it being my path I want to add
("FFmpeg:C:\Users\user\AppData\"
) and adding it with+= C:/Users/etc..
didn't see, the way to go.Another way I tried to add vars through the Powershell commands was using
SetEnviormentVariable
and it seemed to work fine but once I restarted my PC the entry I made with it was gone.Sadly though all in the end all my powershell commands didn't work with subprocess. Whatever command it was I was using here I got:
PS C:\Users\Me123> python >>> import subprocess >>> subprocess.run("$Env:Path", shell=True) The filename, directory name, or volume label syntax is incorrect. CompletedProcess(args='$Env:Path', returncode=1)
-
Can I ship Test-Json from pwsh with my software?
Is it possible to ship cmdlet Test-Json only with my software or a dll that contains it from pwsh? I downloaded the entire pwsh zip file but not sure which one contains it.
My software is going to run on PCs that only have PS 5. I cannot install other software on these machines.
-
Read stderr in bash?
I'm making a BASH script for a setup program made using the
dialog
command. Theman
page for the command says it outputs exit codes to standard error. How do I read standard error without redirecting things to it? Most people say to redirect the standard output to the error, but that's not what I want to do. I want to read it without altering and/or tampering with it in any way. How can I do this? Is it even possible? -
change the exit status of a C/C++ program during atexit callback
I'm looking for a way to change the exit status of a C/C++ program during an atexit callback sequence.
I'm develping some C++ code that registers a book keeping function with atexit. If the program terminates as a result of an exit() call, this book keeping function prints a message if the data was left in an incomplete state. If this is the case, I want to make sure that the exit status of the program is nonzero. This is probably going to be true anyway, but it's also possible to call exit(0).
One solution is to call exit(-1) within the book keeping function that I've registered with atexit. This seems to work, but I think it's also undefined behavior. Does anyone know if this is correct? It's also unclear if this would terminate the atexit callback chain, which would be bad if there's another critical function registered with atexit.
-
Pycharm gives this error: "process finished with exit code -1073741819 (0xc0000005)"
I am trying to use the library tvb-gdist in Pycharm to compute geodesic distances in several meshes. To install it just:
pip install tvb-gdist
However for some reason it works for only some of them. I work with lots of meshes but I will just show you an example with 2 of them to simplify (Here is the link to a folder with the files: https://drive.google.com/drive/folders/1dFKc8wdQuFaUNa3EIKdS7eTj6WVwwZFn?usp=sharing) . The function "gdist.local_gdist_matrix" takes as inputs the vertices and the faces of the mesh, and when executing it for the mesh formed by "vertices2" and "faces2" it works just fine. However when using the mesh formed by "vertices" and "faces" the error appears and the python console shuts down. The entire code is quite big but here is the code I developed to read the files and easily reproduce the error:
import csv import gdist file = open('faces.csv') csvreader = csv.reader(file) faces = [] for row in csvreader: faces.append(row) file.close() file = open('vertices.csv') csvreader = csv.reader(file) vertices = [] for row in csvreader: vertices.append(row) file.close() file = open('faces2.csv') csvreader = csv.reader(file) faces2 = [] for row in csvreader: faces2.append(row) file.close() file = open('vertices2.csv') csvreader = csv.reader(file) vertices2 = [] for row in csvreader: vertices2.append(row) file.close() vertices2 = np.array(vertices2).astype('float64') faces2 = np.array(faces2).astype('int32') aux_distances2 = gdist.local_gdist_matrix(vertices2, faces2, max_distance=12) vertices = np.array(vertices).astype('float64') faces = np.array(faces).astype('int32') aux_distances = gdist.local_gdist_matrix(vertices, faces, max_distance=12)
If you run first until "aux_distances2" you will see that no problem arises and that it gives back the desired matrix. However when runing "aux_distances" the error "process finished with exit code -1073741819 (0xc0000005)" appears and the console crashes. I believe that since it works for some files, the problem cant be with the python version or with something related to the path of the files (they are under the same directory) but anything may be possible. I thought that it might be related with the amount of faces and/or vertices but I did a mesh decimation using the library "quad_mesh_simplify" and the same error appeared after the remesh had been done. I also tried to run it in a notebook in Google Colab to check if Pycharm was the problem but the result was the same: for the second mesh it worked just fine but for the first mesh it crashed. The error showed: "KernelRestarter: restarting kernel (1/5), keep random ports" and then "WARNING:root:kernel 0c24cfc6-3530-4211-a4d2-b147c3444581 restarted". I have tried every solution that I have found and none of them have worked so if anyone could help me I would very much appreciate it.
-
NMAKE : fatal error U107 return code '0x460'
I'm currently using a program to run some simulations, which uses Microsoft Visual Studio 10.0 for compilation. It was running before without any problem but I am now having this issue when I try to run it:
fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Intel Fortran\Microsoft Files\VC\BIN\amd64\link.exe"' : return code '0x460'
Are there any suggestions to solve the problem? (PS: My OS and version is Windows 10 Pro )
-
How to log the HTTP return code with the chi router?
I use
chi
as my router and wrote a simple middleware that logs the request being made:func logCalls(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { log.Info().Msgf("%v â %v", r.URL, r.RemoteAddr) next.ServeHTTP(w, r) }) }
It works great but I am missing the HTTP return code.
The HTTP return code will obviously be available once all the routes are exhausted but at the same time I have to use my middleware before the routes.
Is there a way to hook it after the routing is done, and therefore have the return code I can log?
-
Why does this bash function returns always 0?
I am constructing a wrapper function for bash 5.1 that would wake a command, and indent its output. If the command fails, then I want the wrapper to pass the command return code to the caller
indent() { local com_out=$($* 2>&1) local exit_code=$? echo -e "$com_out" | awk '{ print " â" $0 }' return $exit_code }
However, I don't understand why it always return 0:
$ indent cp a b âcp: cannot stat 'a': No such file or directory $ echo $? 0
If I run the commands one at the time in my shell (zsh), replacing
$*
with an actual command, I get that$exit_command
is indeed 1. -
Build is successful but I kept getting the 'Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 1'
I have 3 classes but I think the problems are occurring between the Main and the Roman Numerals class. . . would also include the class Variables as well. . .
import java.util.Scanner; public class Main{ public static void main (String[] args){ System.out.println("Press 1 for RPS, 2 for Flowchart, 3 for Roman Numerals, 4 for Ascendant"); Scanner Selection = new Scanner(System.in); Variables sel = new Variables(); sel.run = Selection.nextLine(); { if (sel.run.equals("1")){ System.out.println("You have chosen and initialized 1!"); System.out.println("\nAttempting to Connect to RPS Class\n"); RPS JackEnPoy = new RPS(); JackEnPoy.RockPaperScissors(); } else if (sel.run.equals("2")){ System.out.println("You have chosen and initialized 2!"); System.out.println("\nAttempting to Connect to Flowchart Class\n"); Flowchart chart = new Flowchart(); chart.Flow(); } else if (sel.run.equals("3")){ System.out.println("You have chosen and initialized 3!"); System.out.println("\nAttempting to Connect to RomanNumerals Class\n"); RomanNumerals rn = new RomanNumerals(); rn.Numeral(); } else if (sel.run.equals("4")){ System.out.println("You have chosen and initialized 4!"); System.out.println("\nAttempting to Connect to Ascending Class\n"); //Ascending aorder = new Ascending(); //aorder.Ascendant(); } } } }
and the class variables for the other classes
class Variables{ String run; //RPS String guide; String RW = "Rock Smashes Scissors!"; String PW = "Paper Covers Rock!"; String SW = "Scissors Shreds Paper!"; String T = "Impasse!"; //Flowchart int x; int y; int z; boolean YN; }
and this is the Roman Numerals that I've been currently trying to work on whilst the RPS(Rock Paper Scissors) class and Flowchart class worked fine
import java.util.Scanner; import javax.swing.JOptionPane; public class RomanNumerals{ public static void Numeral() { //Declarations String num = " ", roman = " "; char sen = num.charAt(0), hachi = num.charAt(1), jyu = num.charAt(2), ichi = num.charAt(3); int convert; //String from num to Integer convert = Integer.parseInt(num); num = JOptionPane.showInputDialog("Convert from Whole Numbers to Roman Numerals(Maximum:3000)"); //'if' more than 3k then terminate 'else' attempt conversion if (convert > 3000) { //Invalid Message with WARNING_MESSAGE dialog JOptionPane.showMessageDialog (null, "Input had exceeded the maximum of 3000", "RomanNumerals3000", JOptionPane.WARNING_MESSAGE); } else { if (ichi == '1')//0001 roman += "I"; if (ichi == '2')//0002 roman += "II"; if (ichi == '3')//0003 roman += "III"; if (ichi == '4')//0004 roman += "IV"; if (ichi == '5')//0005 roman += "V"; if (ichi == '6')//0006 roman += "VI"; if (ichi == '7')//0007 roman += "VII"; if (ichi == '8')//0008 roman += "VIII"; if (ichi == '9')//0009 roman += "IX"; if (jyu == '1')//0010 roman += "X"; if (jyu == '2')//0020 roman += "XX"; if (jyu == '3')//0030 roman += "XXX"; if (jyu == '4')//0040 roman += "XL"; if (jyu == '5')//0050 roman += "L"; if (jyu == '6')//0060 roman += "LX"; if (jyu == '7')//0070 roman += "LXX"; if (jyu == '8')//0080 roman += "LXXX"; if (jyu == '9')//0090 roman += "XC"; if (hachi == '1')//0100 roman += "C"; if (hachi == '2')//0200 roman += "CC"; if (hachi == '3')//0300 roman += "CCC"; if (hachi == '4')//0400 roman += "CD"; if (hachi == '5')//0500 roman += "D"; if (hachi == '6')//0600 roman += "DC"; if (hachi == '7')//0700 roman += "DCC"; if (hachi == '8')//0800 roman += "DCCC"; if (hachi == '9')//0900 roman += "CM"; if (sen == '1')//1000 roman += "M"; if (sen == '2')//2000 roman += "MM"; if (sen == '3')//3000 roman += "MMM"; JOptionPane.showMessageDialog(null, "Whole Number Form = " + num + "\nRoman Numeral Form = " + roman, "Converted!!!", JOptionPane.INFORMATION_MESSAGE,null); } System.exit(0); } }
and the output went on like this. .
3 You have chosen and initialized 3! Attempting to Connect to RomanNumerals Class Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 1 at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:48) at java.base/java.lang.String.charAt(String.java:1512) at RomanNumerals.Numeral(RomanNumerals.java:9) at Main.main(Main.java:27) Command execution failed.``` I'm still new here and can't figure out on why am I getting this error after initiating 3 as in the RomanNumerals class. .
-
Command execution time in Java
Is there any way to know the execution time of the command? Making
exec
synchronousRuntime rt = Runtime.getRuntime(); Process process = rt.exec(ffmpeg +" -i "+source+" -vcodec h264 -acodec aac "+destination);
the ffmpeg command is taking time so I want to log something after the execution. Is there any way to log the things after the command has executed?