Nsis - changing installation directory - directory

Currently I am in my installing directory say c:\Program File\My installer.I have to execute a demo.bat file that is stored at some other location say c:\Program Files\Temp\example.bat,which I have to go at that location and execute coz my example.bat has some support files that are only stored in Temp folder.
My question is how can I change my installing directory to some other directory, execute demo.bat file and come back to my original installing directory while writing an nsis script?

When talking about "installing directory", I assume you mean current/working directory in the context of a batch file.
push $outdir ;save original path
SetOutpath "$programfiles\temp" ;set currect directory
nsExec::Exec "example.bat"
pop $outdir
SetOutpath $outdir ;restore
There are several ways to execute a batch file (Expand %comspec% and pass it to Exec/ExecWait, or use one of the exec plugins (nsExec,ExecDos,ExecCmd))

Related

Unable to read xml file when using exe4j to package jar into exe

Recently I encountered a problem when using exe4j to package the jar into exe. My xml configuration file is placed in the same directory of the exe, but after the package is completed, the exe will look for the xml file from the temporary folder.
These are the instructions in the exe4j help documentation
For some applications (especially GUI applications) you might want to change >the working directory to a specific directory relative to the executable, for >example to read config files that are in a fixed location. To do so, please >select the Change working directory to: checkbox and enter a directory relative >to the executable in the adjacent text field. To change the current directory >to the same directory where the executable is located, please enter a single >dot.
The error when i running the exe :
[ERROR] In Log's init,cann't read config file, file=/C:/Users/**/AppData/Local/Temp/e4jEA8.tmp_dir1543543191//sys_log.xml
Why is the program not looking for this xml from the exe's sibling directory, and how can I find it from this directory?
If you are using the "JAR in EXE" mode, use
System.getPrpoerty("install4j.exeDir")
to get the parent directory of the executable.

going up a level on a batch file directory

I would like to use on a batch file a directory path that will change from people to people (it is inside a shared folder) and need to access a grand parent folder.
Right now I have the following:
"%CD%\R\R-3.4.2\bin\i386\R.exe" CMD BATCH "%CD%\run.R"
this works when R folder is on the same level as run.R file. But now I want to use the following structure:
-R
-dashboards/folder1/run.R
ie, R folder and dashboards folder are on the same level, and run.R is two levels below inside dashboards folder.
I'm asking for help to wright the correct directory to my R folder on the batch file.
Thanks in advance
If you put the code at the end of this answer in a Windows batch file it will run run.R provided that
run.R is in the current directory and
R is referenced in the registry (which would be the case for a default R install)
Optionally the user can specify the location of R by defining the R_HOME batch variable to point to the current version of R
set R_HOME=C:\Program Files\R\R-3.4.1
... now run batch file ...
They might want to do that if R is not in the registry or if they have multiple versions of R and don't want to use the currently registered one. In the usual case that would not be necessary.
This effectively decouples the location of R and the location of run.R allowing it to be placed anywhere independently of the location of R.
#echo off
setlocal
if not defined R_HOME for /f "tokens=2*" %%a in (
'reg query hklm\software\wow6432Node\r-core\r /v InstallPath 2^>NUL ^| findstr InstallPath'
) do set R_HOME=%%~b
"%R_HOME%\bin\R" BATCH run.R

nsis adds empty folders to the installer

The File below:
; Install common files
SetOutPath "${GameDir}\Mopy"
File /r /x "*.bat" /x "*.py*" /x "w9xpopen.exe" /x "Wrye Bash.exe" "Mopy\*.*"
filters out some directories that contain python files but still those directories are created (although empty, or containing empty subdirectories) when I run the installer. Those folders need to be included to the installer (if I get the terminology correct at "compile time") cause the installer has an option to install the python version of the program. I can't come up with a way to not add these empty folders. Is there some wildcard I could use to that purpose or should I go and remove the files on installation (using RMDir ?) ?
I'd say you have two options and one is indeed RMDir if you are OK with it possibly removing empty folders that the user created.
The other option is to not use File /r ... and instead use !system to execute something like a batch file that generates a text file with individual File instructions that you can !include. It would look something like this:
!tempfile files
!system '"mygeneratefilelist.bat" "${files}"'
!include "${files}"
!delfile "${files}"
and the batch file would use FOR and/or DIR to list and ECHO the File commands to %1...

Error from 7z cannot open <file>.tmp Permission denied

I have an archiving script that uses 7z -tzip -aoa and it runs on unix and works fine. But when run through Autosys, it always fails when trying to archive a second file to an existing archive. The error is:
7-Zip 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
p7zip Version 9.20 (locale=C,Utf16=off,HugeFiles=on,8 CPUs)
Scanning
Updating archive
20150807.zip
Error:
7-Zip cannot open file
20150807.zip.tmp
Permission denied
It doesn't tell me where it's having permissions with that tmp file, so I don't know where to look. I've set all the permissions to any folders that I thought it might be using to 777, but the problem persists. It works great when not using Autosys.
I found the comment below but it seems to be relevant only to Windows. I'd like to know how I can make this work on UNIX.
I tried to search for a while on the net, but couldn't find any help, so here I am.
My first problem is when I try to compress a folder in C:// with the context menus (7-zip > Add to "xyz.zip"), I get the error : "Access is denied. 7-zip cannot open file "xyz.zip.tmp"
I can however open the file manager in the 7-zip folder ("7zFM"), run as administrator and compress the said file to .zip.
It seems to be a security issue about C:// directory, since it seems that I can compress other files and folders just fine.
Any help?
Link
Shell
Shell
2012-07-29
You have guessed right. You can either 1) run 7-Zip as administrator or 2) set the working directory in 7-Zip File Manager (Tools->Options->Folders) to an unprotected one (for example, clear the checkbox there) and use the "Add to archiveā€¦" menu and create the archive in an unprotected directory.
Set the working directory using the -w switch.
7z does not use current directory (the one you get by pwd) as a working directory. It uses the one that the resulting archive is going to be created at.
For example:
/tmp $ 7z a /folder.7z /folder
will ignore the fact you're in /tmp and will first create a tmp file in / and then put the result in the / no matter what you current folder is.
If you don't have access to create files in / but you do have access to update the archive that's already there (a very valid scenario) you're going to get exactly what you get:
/tmp $ 7z a /folder.7z /folder
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=en_US.utf8,Utf16=on,HugeFiles=on,64 bits,4 CPUs Intel(R) Core(TM) i7-7500U CPU # 2.70GHz (806E9),ASM,AES-NI)
Open archive: /folder.7z
--
Path = /folder.7z
Type = 7z
Physical Size = 150
Headers Size = 150
Solid = -
Blocks = 0
Scanning the drive:
1 folder, 2 files, 0 bytes
Updating archive: /folder.7z
Items to compress: 3
Error:
cannot open file
/folder.7z.tmp
Permission denied
System ERROR:
Unknown error -2147024883
Also, in case you're omitting the archive name from the command line, it's going to use directory of your source.
For example, when you do this:
7z a /folder
it is going to use / as a working directory - it will attempt to create temp file in / and will put the resulting archive there as well.
To fix that just make sure that the archive name is in your command line and that you have file create permission to the folder the archive is going to be created (sometimes you have access to update the archive itself but can't create new files in the dame folder)

Untar a file in an OS X directory with QProcess

I'm trying to untar a file with QProcess that's in a directory returned by QDir::tempPath(), as follows:
extract.start("tar", QStringList() << "-xvzf" + QDir::tempPath() + "/thefile.tar.gz");
I get the correct output for an extraction by looking at the standardOuput for the QProcess but there's no file extracted at the end. Manually running tar from a shell works fine on the file so I know it's not corrupt, I'd have assumed a permissions issue but I'm actually downloading the file with the application to the temporary directory so the application should have write access.
Edit: I've also now tried it with the file in the home directory, it's definitely there but I get the same results as it being in the temp directory, verbose output indicating success but no resulting file.
You need to set the working directory, which by default, is likely to be the folder of the executable's binary.
You can set the working directory with QProcess::setWorkingDirectory

Resources