Untar a file in an OS X directory with QProcess - qt

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

Related

Not understanding the path of files in Python exe output

my Python project works in editor. I get .exe output from Python (.py) program. The .exe file could not understand the path of the files.
import os
a = os.getcwd() + "\\Logs\\" # Find the log directory
# Read the text in the Paths.txt file inside the logs directory
b = open (a + "Paths.txt", "r").read()
When the code is executed in the editor, the text inside the file is read and the file path is understood. But when executing the .exe file, the program can not detect the path of the log file.
Log file path at runtime (in editor or .py): currect and understood
'C:\\Users\\mohammad\\Desktop\\projects\\Logs\\Paths.txt'
Log file path at runtime (in .exe file): not currect
'C:\\Users\\mohammad\\Desktop\\projects\\dist\\Logs\\Paths.txt'
I tried some methods such as short route but it did not work.
Also, due to my problems, I output Python file as follows:
pyinstaller.exe --onefile --add-binary "C:\\Users\\mohammad\\Desktop\\projects\\pythoncom310.dll\\;." Start.py
And i'm using version 3.9 of Python and the VScode editor. Thanks for your time

How to put an R script into a dockerfile?

I am trying to add my R script into a dockerfile. The beginning of the file (loading base image, installing necessary packages) works fine when I run it in my terminal, but I keep getting this error when it gets to the line that contains the R script I want to run:
Step 15/17 : COPY /Users/emma/Documents/folder1/examples/question-1/model-1.r .
COPY failed: stat /var/lib/docker/tmp/docker-builder376572603/Users/emma/Documents/folder1/examples/question-1/model-1.r: no such file or directory
I am already running the terminal out of the "question-1" directory (my shell command looks like this) :
Emmas-MacBook-Air-2:question-1 emma$
and the R script file "model-1.r" is in that folder. What am I doing wrong in detailing the path to the R script? Do I have to somehow transform the script before adding it to the dockerfile?
Thank you
I believe, that you have to specify relative (to your build folder) path to copy from. Source:
Multiple resources may be specified but the paths of files and directories will be interpreted as relative to the source of the context of the build.
And file to copy should be inside context of the build. So if your Dockerfile is located in folder A, then the objects you would like to copy should be placed in the folder A or it's subfolders.

Creating temp folder in Linux

I was using R installed on a Linux server using SSH. Everything was fine, but now I have been denied access to temp folder and if I am loading R it is giving error cannot create 'R_TempDir', as it can't create the temp folder.
Can you please tell me how to create own local temp folder so that R can create temporary directory there ?
You can try to set one of these environment variable :
TMPDIR, TMP, TEMP:
Consulted (in that order) when setting the temporary directory for the session: see tempdir. TMPDIR is also used by some of the utilities see the help for build
by doing for instance :
export TMPDIR=/tmp
source
Hope this answers.
From what I understand,
I just thought that you could use .bashrc files in your /home/username/ directory
~# nano /home/username/.bashrc
You can put the command to create the folder inside this .bashrc file by just adding this line mkdir /your/dir/path/yourDir
This file is just like an autorun file which run everytime you upstart your linux server
But this is just working per user setting

Changing R options persistently

I want to change the prompt in R from > to R> and I know I should use the options command options(prompt="...") and it works, but then when I restart R the prompt is back to >.
Is there anyway to save the change so that it sticks?
Use .Rprofile file:
You can customize the R environment through a site initialization file or a directory initialization file. R will always source the Rprofile.site file first. On Windows, the file is in the C:\Program Files\R\R-n.n.n\etc directory. You can also place a .Rprofile file in any directory that you are going to run R from or in the user home directory.
At startup, R will source the Rprofile.site file. It will then look for a .Rprofile file to source in the current working directory. If it doesn't find it, it will look for one in the user's home directory. There are two special functions you can place in these files. .First( ) will be run at the start of the R session and .Last( ) will be run at the end of the session.
More details are here

Nsis - changing installation 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))

Resources