Why does my 7zip command now get a "Cannot find archive name" error - powershell

Without problems I've been using the following 7zip command on Appveyor CI in a .bat file using 7zip 21.07 running on Windows Server 2019, and also with earlier Windows Server & 7z versions:
7z -owin-oclcpuexp-2021.12.9.0.24_rel e win-oclcpuexp-2021.12.9.0.24_rel.zip
The identical command in a Powershell script on GitHub Actions CI using 7zip 22.01 running on Windows Server 2022 gets this error:
7-Zip 22.01 (x64) : Copyright (c) 1999-2022 Igor Pavlov : 2022-07-15
Command Line Error:
Cannot find archive name
I've tried running it from cmd.exe
cmd.exe /C 7z -owin-oclcpuexp-2021.12.9.0.24_rel e win-oclcpuexp-2021.12.9.0.24_rel.zip
and also tried putting the command before the switch
7z e win-oclcpuexp-2021.12.9.0.24_rel.zip -owin-oclcpuexp-2021.12.9.0.24_rel
but I still get the error. win-oclcpuexp-2021.12.9.0.24_rel.zip is present in the current directory and has the expected size.
EDIT: For the sake of completeness I should say that the name is taken from an environment variable. The actual command has $env:OPENCL_SDK_NAME instead of win-oclcpuexp-2021.12.9.0.24_rel. In the .bat file the reference was, of course, %OPENCL_SDK_NAME%. I have verified that the variable has the expected value.
Why did this command stop working?

I was able to reproduce the problem on my local Windows box so with the help of ProcessMonitor, thanks Lex Li, I figured out what was happening. It's all down to Powershell handling of variable expansion. As a relative newbie to PS and long time bash/sh user I find PS's behavior surprising.
The actual command I had was
7z -o$env:OPENCL_SDK_NAME e $env:OPENCL_SDK_NAME.zip
I also had a preceding curl command using the same env. var. Because this worked it helped mask the issue.
curl.exe -s -S -L -O $env:OPENCL_SDK_HOME/$env:OPENCL_SDK_NAME.zip
So what is it? There are actually 2 problems:
With -o$env:FOO the variable is not expanded so the application sees exactly -o$env:FOO.
When seeing $env:FOO.zip PS substitutes an empty string, hence the Cannot find archive name error. I would never have spotted this without ProcessMonitor as the similar expansion in thecurl command was working. It turns out that PS does expand the variable in the case of foo/$env:FOO.zip. Utterly bizarre.
My fix is to add quotes around the variables. For safety I added them to the curl command as well. I don't know if there are other better ways of fixing this.
curl.exe -s -S -L -O "$env:OPENCL_SDK_HOME/$env:OPENCL_SDK_NAME.zip"
7z -o"$env:OPENCL_SDK_NAME" e "$env:OPENCL_SDK_NAME.zip"

Related

Error running Metricbeat.exe commands in powershell

I am trying to install Metricbeat on a Windows 10 machine so we can start monitoring it. When I open Powershell and run the following commands:
PS > .\metricbeat.exe modules list
I get the error
I copied that command as is from the Metricbeat documentation. I have seen videos on youtube of people running similar commands successfully. Please, why am I getting that error and what can I do to get my metricbeat.exe powershell commands to work?
You're copying the command TOO literally.
you've entered in the prompt PS > .\metricbeat.exe modules list
where you should have entered .\metricbeat.exe modules list
the latter executes modules list action against an application named "metricbeat.exe" located in .\ which indicates the current directory.
the former executes a redirection > of the output of an application named PS or get-process with input of .\metricbeat.exe modules and an argument of list.
wherever you copied this command from intended "PS >" to represent the beginning of the prompt and you don't need to include it.
Just like the error says... :P

How to execute custom fish scripts in custom path folder

I'm having trouble executing a fish shell script I created. I added it to a custom path I added using fish_add_path. The folder appears just fine in $fish_user_paths and $PATH, and i've CHMOD +x the file, but when I type the name of the file, (which is pickc ath the moment), it can't find the command. How do I add fish scripts to the path and execute them like any other cli command (e.g. pickc)?
The content of the script is:
#!usr/bin/fish
colorpicker --short --one-shot --preview | sed -z 's/\n//g' | xclip -selection c
pkill picom
picom -b
I can execute the script just fine with the fish -c pickc command, but I can't execute with ./pickc, which gives me the error
Failed to execute process './pickc'. Reason: The file './pickc' does not exist or could not be executed.
I have doubly confirmed that the path in the $PATH and $fish_user_variable variable does lead to the folder containing the script.
Edit: I noticed that my paths were all really messed up somehow. The below answer does fix the issue of not being able to execute it, so thanks
You have mistyped your shebang. Switch
#!usr/bin/fish
to
#!/usr/bin/fish
or whatever path which fish shows.

Getting error in command line in Tesseract in Windows

I am following this documentation-https://code.google.com/p/tesseract-ocr/wiki/TrainingTesseract3
I am trying to make a font for my language using this command-
training/ text2image --text=training_text.txt --outputbase=bn.Boishakhi.exp1 --font=Boishakhi --fonts_dir=C:\
I am getting this error
"Training is not recognized as external or internal command", on windows xp sp3 command line.
I am also having another problem.I ran tesseract successfully in windows xp sp3(English default traindata) but I cannot run it from command line to generate output in Windows 7 and 8.1. The commands I used are as follows:
cd C:\
cd Program Files
cd Tesseract-OCR
tesseract C:\Document.tif output -l eng
Please help.
I tried to change /(slash) to \ (backslash) but now the new error is "Cannot find the path specified"
As far as running in windows 7 or 8.1 is concerned, the error is "cannot create output file output.txt"
The first message means that the executable training was not found on the path. If the required executable was text2image then the space should be removed and the correct directory-separator used. \ separates directories in Windows; / introduces switches.
So training\text2image... should cure the problem, provided text2image is an executable found in training which is a subdirectory of whatever is the current directory, or you could use an absolute path, "C:\wherever\you have installed\tessteract\training\text2image" - and "note the quotes" that are required if the path to the name includes spaces (optional otherwise.)
As for your second question, you have unaccountably provided no information about any error messages you received, or how the system responded, so any response will be a guess. It may have something to do with the default protected status of the root directory C:\ and it may not. Please edit the question to include the error message or run report.

Perl running a batch file #echo command not found

I am using mr on Windows and it allows running arbitrary commands before/after any repository action. As far as I can see this is done simply by invoking perl's system function. However something seems very wrong with my setup: when making mr run the following batch file, located in d:
#echo off
copy /Y foo.bat bar.bat
I get errors on the most basic windows commands:
d:/foo.bat: line 1: #echo: command not found
d:/foo.bat: line 2: copy: command not found
To make sure mr isn't the problem, I ran perl -e 'system( "d:/foo.bat" )' but the output is the same.
Using xcopy instead of copy, it seems the xcopy command is found since the output is now
d:/foo.bat: line 1: #echo: command not found
Invalid number of parameters
However I have no idea what could be wrong with the parameters. I figured maybe the problem is the batch file hasn't full access to the standard command environment so I tried running it explicitly via perl -e 'system( "cmd /c d:\foo.bat" )' but that just starts cmd and does not run the command (I have to exit the command line to get back to the one where I was).
What is wrong here? A detailed explanation would be great. Also, how do I solve this? I prefer a solution that leaves the batch file as is.
The echo directive is executed directly by the running command-prompt instance.
But perl is launching a new process with your command. You need to run your script within a cmd instance, for those commands to work.
Your cmd /c must work. Check if you have spaces in the path you are supplying to it.
You can use a parametrized way of passing arguments,
#array = qw("/c", "path/to/xyz.bat");
system("cmd.exe", #array);
The echo directive is not an executable and hence, it errors out.
The same is true of the copy command also. It is not an executable, while xcopy.exe is.

How is this zip command being used in perl?

I found this piece of code in perl
system("zip $ZIP_DEBUG -r -9 itvlib.zip $include $exclude");
However I don't understand how it is working. I mean system() is used to fire 'system' commands right ? So is this 'zip' command used here a 'system' command ?
But I tried firing just the following on the command prompt;
zip $ZIP_DEBUG -r -9 itvlib.zip arg1 arg2
It didn't work !
it gave the following error:
'zip' is not recognized as an internal or external command,
operable program or batch file.
Well this shouldn't have happened, since the command seems to use 'zip' as a system command. So this makes the command 'zip' mysterious
Can you please help me to understand this command with all its parameters?
It's probably not working since you're not replacing things like $ZIP_DEBUG with their equivalent real values. Within Perl, they will be replaced with the values of the variables before being passed to the system call.
If you print out those Perl variables (or even the entire command) before you execute that system call, you'll find out those real values that you need to use. You can use the following transcript to guide you:
$ perl -e '
> $ZIP_DEBUG = "xyzzy";
> $include = "inc_files";
> $exclude = "exc_files";
> print "zip $ZIP_DEBUG -r -9 itvlib.zip $include $exclude";
> '
zip xyzzy -r -9 itvlib.zip inc_files exc_files
For details on how system works, see here. For details on what zip needs to function, you should just be able to run:
man zip
from a command line shell (assuming you're on Linux or its brethren). If, instead, you're on a different operating system (like Windows), you'll have to figure out how to get the zip options out. This may well be as simple as zip -? of zip -h but there's no guarantee that will work.
If it's the same as the Info-ZIP zip under Linux (and it may be if you have the -9 and -r options and your exclude variable starts with -x), then zip -h will get you basic help and zip -h2 will give you a lot more.
system("zip $ZIP_DEBUG -r -9 itvlib.zip $include $exclude");
is running a program named zip (probably zip.exe) somewhere on the path. $ZIP_DEBUG, $include, and $exclude are Perl variables that are interpolated into the command line before the command is run.
If the system call works in the Perl script, but zip -? gives the 'zip' is not recognized as an internal or external command, operable program or batch file error, then the PATH of the Perl script must be different than the PATH in your command prompt. Or, there might be a zip command in the current directory when Perl executes the system command. (In Windows, the current directory is an implicit member of your PATH.)
To see what the PATH is for the Perl script, you can add a print "$ENV{PATH}\n"; before the system command. To see what the PATH is in your command prompt, type PATH.
Yes, zip is a system command. The variables $ZIP_DEBUG and such are perl variables that are interpolated to the command before launching zip.
To debug what the actual call is, try adding:
print("zip $ZIP_DEBUG -r -9 itvlib.zip $include $exclude\n");
See perldoc for details on system.