Change logfile path with batch file - batch-file

From the documentation of Unity you can change the logfile path by adding
-logFile <pathname>
I tried doing that with a batch file:
setlocal
cd /d %~dp0
Game.exe -batchmode -logFile<D:\Test\>
This just starts the Windows Command Prompt and nothing happens. Also i don't know how to change the <pathname> of the -logfile so that it uses the path of the batch file.

Thanks to all your comments, i solved it today:
setlocal
cd /d "%~dp0"
Game.exe -logFile ./Logs/output_log.txt
this is working fine for me.

Related

Why can't my batch script create .txt files when elevated?

This is pretty weird. I have a simple batch script:
#echo off
#echo test> text.txt
When I run it without elevated permissions it creates "text.txt", which contains "test" inside it.
However when I run the same batch file WITH elevated permissions it does nothing. Why?
when you run in with elevated permissions, it cd to C:\WINDOWS\system32 so you need to cd earlier in your script
#echo off
cd C:\path\where\you\want\to\create\your\file
#echo test> text.txt
you can also do this if you want the file to be created in the folder the batch is in
#echo off
cd %~dp0
#echo test> text.txt
Try this one
#echo off
echo.
cd N:\myfolder
N:
echo hi>>123.txt

CMD/FTP to create folder using to today date & connect ftp download into created folder

I'm new to this cmd/FTP command. I would like to create a new folder at my local directory using today's date and connect to FTP to download the specific file to the newly created folder. If I manually type in command one by one at cmd, it has no issue. But when I use a batch file to run, my command stopped at FTP.
setlocal enableextensions
set name=%date:~-10,2%"-"%date:~7,2%"-"%date:~-4,4"_"job%
mkdir C:\%name%
cd C:\%name%
ftp
open 192.168.31.93
*user*
*password*
binary
cd *directory*
mget -i *.*
I did try to separate my command to two batches;
1. folder creation
2. FTP download but the file downloaded didn't go into the folder I created. the downloaded file went to C:\Document & Settings.
main batch file
#echo off
call rename.bat
ftp -i -s:ftp.txt
rename.bat
setlocal enableextensions
set name=%date:~-10,2%"-"%date:~7,2%"-"%date:~-4,4%"_job"
mkdir c:\%name%
cd c:\%name%
ftp.txt
open 192.168.31.93
*user*
*password*
binary
cd *directory*
mget *.*
close
Another method I try is using '!' when in FTP environment, then create a folder then exit back to FTP environment. This method again doesn't work with the batch file. Please help
It seems that with command extensions enabled, the working directory set by a child batch file is lost, then the batch file exits.
I'm not sure how to solve it, but you actually do not need the rename.bat file to be a separate file. This "main batch file" should work:
#echo off
setlocal enableextensions
set name=%date:~-10,2%"-"%date:~7,2%"-"%date:~-4,4%"_job"
mkdir c:\%name%
cd /d c:\%name%
ftp -i "-s:%~dp0\ftp.txt"
Also note the /d added to cd. Without that your batch will not work when started from another drive. You also have to use %~dp0 to refer to the batch file folder for the ftp.txt. As at the time ftp is called, you have changed to the target directory.
You possibly do not even need the command extensions to be enabled. So simply removing the setlocal enableextensions might solve the problem too. Though you still need the %~dp0 and /d.
I've decided to post this, although similar to the answer given, there are a couple of differences.
It creates the text file, then deletes it, (this keeps everything more portable).
I have corrected your directory name, (because of a typo).
#Echo Off
Set "Name=%DATE%"
Set "Name=%Name:~-10,2%-%Name:~-7,2%-%Name:~-4%_job"
MD "C:\%Name%" 2>Nul
CD /D "C:\%Name%" || Exit /B
( Echo open 192.168.31.93
Echo *user*
Echo *password*
Echo binary
Echo cd *directory*
Echo mget *.*
Echo close
)>"ftp.txt"
FTP -i -s:ftp.txt
Del "ftp.txt" 2>Nul
Exit /B

Loop in directory using awk script that can be running using cmd line

I want to do some loop on files inside subfolders using awk script that I'm running it from cmd line script.
I'm using this code inside my cmd:
for /r %%I in (*.txt) do awk -f D:\Main\command.awk %%~fI
pause
But I have these error rise:
'awk' is not recognized as an internal or external command, operable
program or batch file.
But when I write it down manually on cmd line, it works just fine.
Does anyone know what is wrong with this?
Thank you.
Regards,
Bams
Sorry for late update.
Here's the code that I made in cmd script.
#echo off
pushd "%~dp0"
for /r %%I in (*.txt) do C:\Progra~2\GnuWin32\bin\awk -f command.awk %%~fI >> result.csv
pause
and it works, so basically I notice the error was about working directory.

Start *.exe from specific dir, in specific dir

First, sorry for my English, but I try my best to explain the situation. I'm no real pro about *.bat files, but I know the basics to run exe files with it.
bat-script:
setlocal
cd "%~dp0"
start "" "%~dp0\Lang\Language.exe"
I need to start "Language.exe" inside "%~dp0" (root), where the *.bat is saved. I read many different questions/answers on stackoverflow, but none worked. The "Language.exe" is saved in "%~dp0\Lang", but it need to be run in "%~dp0" or it won't work.
The *.exe will only work from root (%~dp0), nowhere else. And there can't be any real folder structures like C:\root\Lang\Language.exe, because it have to work for others as well.
*.bat location --> root
file to start at *.bat location --> root\Lang\Language.exe
The "Language.exe" converts a language to some other with a diff-patch. I mean the *.bat starts the *.exe (also with other command variations I tried), but it says, that it can't find the files to patch. Yeah, because the so called working directory is not right (need to be "root"). But all that without moving the *.exe or anything, it should only be started in "root" from "root\Lang\Language.exe", nothing else.
EDIT:
As a workaround, I now simply move the "Language.exe", start it and move it back.
setlocal
cd "%~dp0"
move "Lang\Language.exe" "%~dp0" >nul
ECHO Starting patch...
timeout /t 1 >nul
start "" /wait "Language.exe"
move "%~dp0\Language.exe" "Lang" >nul
Set working directory
It is possible that you run into the issue discussed at In Batch file ~dp0 changes on changing directory.
I can think of 3 solutions.
Solution 1:
cd /D "%~dp0"
start "Language Patch" Lang\Language.exe
First the working directory is changed and then the EXE is called with a relative path. Parameter /D is necessary if current working directory on start is on a different drive than location of the batch file.
Solution 2:
setlocal
set "BatchPath=%~dp0"
cd /D "%BatchPath%"
start "Language Patch" "%BatchPath%Lang\Language.exe"
endlocal
The path of the folder containing the batch file is first assigned to an environment variable. This path ends with a backslash. Therefore the EXE can be called without a backslash before Lang.
Solution 3:
setlocal EnableExtensions
pushd "%~dp0"
start "Language Patch" Lang\Language.exe
popd
endlocal
push and popd are used in case of folder with batch file is not on a drive with a drive letter, but on a public network share. Read help of pushd and popd output by running in a command prompt window pushd /? and popd /? for details about those 2 commands.
Application directory used
But all those variants above do not help if Language.exe does not search for the files to patch in current working directory, but in its own application directory.
For example if Language.exe is written using Qt and uses inside the static function QCoreApplication::applicationDirPath() instead of searching for the files in current working directory, i.e. use QDir::currentPath() respectively search for the files without path and without changing working directory first.
Or if Language.exe is written using .Net and the application directory is used with one of the methods explained at How can I get the application's path in a .NET console application? instead of using current working directory.
In this case the best solution is copying Language.exe into the directory with the files to patch and delete the executable after it has terminated itself after patching all the files.
setlocal EnableExtensions
pushd "%~dp0"
copy /Y Lang\Language.exe .>nul
echo Starting patch...
Language.exe
del Language.exe
popd
endlocal

How to run any program with batch file from any specific location

I wrote a batch file for open a specific program but it is not working.I wrote this :
#echo off
C:\Windows\System32\cmd.exe /K "cd /d C:\Program Files (x86)\HTC\HTC Sync Manager\"
start HTCSyncManager.exe
When I run the batch file only this window come, program do not start. How to fix this
#echo off
For /r c: %%f in (path goes here /HTCsyncmanager.exe) do (
start "%%f"
"%%f"
)
Remove the invoking of cmd.exe. All that's doing is starting a new instance of the command processor, which is not what you need at all. (You probably don't need the start, either.)
#echo off
cd /d "C:\Program Files (x86)\HTC\HTC Sync Manager\"
HTCSyncManager.exe
#echo off
start "HTCSyncManager" "C:\Program Files\(x86)\HTC\HTC Sync Manager\HTCSyncManager.exe"
This will open HTCSyncManager.

Resources