I keep getting "Access Denied" when I try to install 7zip from the installer executatble I have downloaded - perl

I am trying to install 7-Zip if its already not installed in my Win7 systems using a Perl script.
# Check if 7-Zip is installed or Not.
if (!(-e "C:\\Program Files\\7-Zip")){
print "\n 7-Zip is not installed. Downloading ... \n"
system("wget http://downloads.sourceforge.net/project/sevenzip/7-Zip/9.20/7z920.exe?r=&ts=1392082197&use_mirror=softlayer-dal");
print "\n Installing.. \n";
system("7z920.exe /S /D=\"C:\Program Files\7-Zip\"");
}
It is downloading the file I need (7z920.exe) to the PWD, but it doesn't install. I keep getting the command line error, "Access Denied". Even if I run the script in Administrator mode on command line.
In fact, if I simply go the system path were 7z920.exe on command line and attempt to call the .EXE, i get the same denied error. It won't install. But if I click on it from the folder, it allows me to install it?! Why is that I may double-click and install from folder, but cannot call the executable from the same path from command line and not install it?
C:\>7z920.exe /S /D="C:\Program Files\7-Zip"
Access is denied.
Can you help me? How do I install this using my script? or from a batch file?

When I run that wget command, I get a file called 7z920.exe#r=&ts=1392082197&use_mirror=softlayer-dal. So I would recommend
Use wget's -O option to force the downloaded file to have the filename you want.
wget -O 7z920.exe http://downloads.sourceforge.net/project/...
I don't know what's in your PATH, so precede your command with the current path.
system(".\\7z920.exe /S /D=...");
Be careful about how you escape special characters in Perl inside double quotes. Try one of:
system(".\\7z920.exe /S /D=\"C:\\Program Files\\7-Zip\"");
system('.\7z920.exe /S /D="C:\Program Files\7-Zip"');

Related

PowerShell executing .bat files with in the same session

I am installing a software in silent mode using PowerShell. Installation was done successfully but when I am trying to execute few batch files I am getting some exceptions.
Could not find the files for the given pattern. The system can not find the specified path.
My command inside my PowerShell:
$inst_path = \\My installed drive (c:\program files\mysoftware\)
& $inst_path\start-service.bat install
But when I closed the PowerShell ISE and executing the same command it is working without any exceptions, so can someone help me overcome this?
You've got a double slash in the path to the bat file, both the $inst_path variable and the path you construct.
You're trying to call c:\program files\mysoftware\\start-service.bat - which is going to fail.
Try this instead:
$inst_path = "c:\program files\mysoftware"
& "$inst_path\start-service.bat" install

Message " 'echo.' is not recognized as an internal or external command, operable program or batch file." when starting shell

When starting my shell, I get a message :" 'echo.' is not recognized as an internal or external command, operable program or batch file." I am not sure where it comes from. The problem is, that when I run my perl scripts as external tools in eclipse, this message is also printed in the eclipse console after the output of the scripts. How can I get rid of it?
Remove the . at the end of echo. command used in the perl script.
To locate the perl script involved in a directory and all sub directories, use:
grep -irH "echo[.]" .
This other command-line below automatically update all perl scripts found in current directory and sub directories; it replaces any echo. encountered with echo
WARNING: backup the directory before running the command-line below:
find . -type f -print0 | xargs -0 -I xxxx sed -i 's/echo[.]/echo/g' xxxx
Barbara Jensen provided the best answer in a comment (quoted below)
Echo. in Windows CMD should print a blank line, but in some situations, it returns the "is not recognized as an internal or external command..." error. I suspect it's cmdextensions or similar.
Barbara says "echo/" replaces it and this worked perfectly for me. Thanks B.
echo. is supposed to display a blank line; it is not invalid Windows command. I have used this in batch files for at least 15y and it went bad for me very recently. Interestingly for me, its working sometimes (the windows that I've set up for compiling) and not others (fresh ones). If I change the echo. to echo/ in my batch files, they work again. – Barbara Jensen Feb 14 at 13:55
Since this is the top search hit when searching for the error message: one can also end up with this intermittent error message when the current directory contains a file named echo, even if it's empty. It's easy to diagnose this possibility: move to another directory and check if echo. works. It should normally print an empty line in cmd, where echo is a built-in command. If echo. works in other directories: rename or remove the file called echo.
Figure out which one of your shell startup files contains the misspelling and remove it (the misspelling, not the file).

executable file must be placed in either the current working directory or somewhere in the command path

I'm installing a command line program called plink that recommends this:
The PLINK executable file should be placed in either the current
working directory or somewhere in the command path. This means that
typing "plink" or "./plink" at the command line prompt will run PLINK,
no matter which current directory you happen to be in. PLINK is a
command line program -- clicking on an icon with the mouse will get
you nowhere.
I have the PLINK executable file. What should I do next?
Run 'chmod +x plink' to grant the file execution rights.

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.

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.