I have a batch file that executes another batch file with a couple command line arguments. This is the command:
call "C:/Program Files (x86)/salesforce.com/Data Loader/bin/process.bat", "D:/Scripts/CS Dashboard/DataLoader", "casesByCategory_LM"
My problem is that upon execution, it says "System cannot find the path specified". I realize it is because I am specifying a filepath on a separate drive D:
I tried adding the filepath to the system environment variables but that didn't do any good.
I also tried running this from a command prompt opened from the D: drive which also didn't work.
process.bat is a file provided to me by SalesForce to use their DataLoader. These are the contents:
#echo off
if not [%1]==[] goto run
echo.
echo Usage: process ^<configuration directory^> ^[process name^]
echo.
echo configuration directory -- directory that contains configuration files,
echo i.e. config.properties, process-conf.xml, database-conf.xml
echo.
echo process name -- optional name of a batch process bean in process-conf.xml,
echo for example:
echo.
echo process ../myconfigdir AccountInsert
echo.
echo If process name is not specified, the parameter values from config.properties
echo will be used to run the process instead of process-conf.xml,
echo for example:
echo.
echo process ../myconfigdir
echo.
goto end
:run
set PROCESS_OPTION=
if not [%2]==[] set PROCESS_OPTION=process.name=%2
..\Java\bin\java.exe -cp ..\dataloader-29.0.0-uber.jar -Dsalesforce.config.dir=%1 com.salesforce.dataloader.process.ProcessRunner %PROCESS_OPTION%
:end
Remove the commas and use backslash as path separator.
call "C:\Program Files (x86)\salesforce.com\Data Loader\bin\process.bat" "D:\Scripts\CS Dashboard\DataLoader" casesByCategory_LM
If this does not work then you should post your process.bat code
Related
The code below checks if there is a folder called Made_files if so it will cd to that folder and make a new file using variables
Else it will make a folder called Made_files THEN cd to that folder and run the code but at the moment all it does is flash up then close instantlly can someone help
if EXIST Made_files (
cd Made_files
set /p name=Name of file:-
set /p Filetype=Type of file(txt, bat js):-
echo #echo off > %name%.%Filetype%
echo color 0a >> %name%.%Filetype%
) else mkdir Made_files
cd Made_files
set /p name=Name of file:-
set /p Filetype=Type of file(txt, bat js):-
echo #echo off > %name%.%Filetype%
echo color 0a >> %name%.%Filetype%
echo ___
pause
#ECHO OFF
SETLOCAL
:: Ask for filename and type
set /p name=Name of file:-
set /p Filetype=Type of file(txt, bat js):-
:: Required file to be located in "Made_files"
SET "subdir=Made_files"
MD ".\%subdir%" 2>NUL
CD "%subdir%"
(
echo #echo off
echo color 0a
)> %name%.%Filetype%
echo ___
pause
GOTO :EOF
What your code does:
If the subdirectory already exists, switch to that directory, ask for the filename&type, then create a new file using the requested data. Otherwise, create the directory.
THEN
Change to the subdirectory again (so if made_files already existed, try to change to .\made_files\made_files), ask for the filename and type and create the file.
===
BUT Please read Stephan's DELAYEDEXPANSION link. Since you are not using delayedexpansion, when the if statement is parsed (and the if statement continues until the end of the else clause) the values of the variables name and filetype are replaced by their values when the statement was parsed (~verified), NOT as they were input, so the destination filename will be nothing.nothing , which is "." - a directory-name (sort-of).
It's likely that this is the source of the drama.
When you use the point-click-and-giggle method of executing a batch, the batch window will close if a syntax-error is found or the script runs to completion. You can put a pause after statements and home in on the error, but better to open a 'command prompt' and run your batch from there so that the window remains open and any (error) messages will be displayed.
===
So : the code I suggest:
Asks for the file name and type.
Attempts to make the directory. If it already exists, this will generate an errormessage which is suppressed by the 2>nul.
switches to that subdirectory.
Creates the file.
Note that if the echoes are surrounded by parentheses, then their output is combined and directed to the file, saving a plethora of redirect-to-file clauses.
I hope you can help me.
I am using youtube-dl on windows (youtube-dl.exe)
Downloading the video works great and also just the audio. But what i want is for it to save the audio file in a different place eg. C:\Users*******\Desktop
I made a batch file with this code:
:audio
cls
echo.
echo.
echo Your audio vill be downloaded and saved as a .mp3 format
echo.
echo.
set /p audio=Enter Video URL here:
cls
youtube-dl.exe --extract-audio --audio-format mp3 --output C:\Users\*******\Desktop\(ext)s.%(ext)s %audio%
pause
cls
echo.
echo.
echo.
echo.
echo Your audio has now been downloaded.
ping localhost -n 3 >nul
exit
and then it gives me this
Usage: youtube-dl.exe [OPTIONS] URL [URL...]
youtube-dl.exe: error: You must provide at least one URL.
Type youtube-dl --help to see a list of all options.
Press any key to continue . . .
It works fine if i use this but it saves it in the same folder.
:audio
cls
echo.
echo.
echo Your audio vill be downloaded and saved as a .mp3 format
echo.
echo.
set /p audio=Enter Video URL here:
cls
youtube-dl.exe --extract-audio --audio-format mp3 %audio%
pause
cls
echo.
echo.
echo.
echo.
echo Your audio has now been downloaded.
ping localhost -n 3 >nul
exit
Also please keep in mind that it also uses ffprobe.exe and ffmpeg.exe (They are both in the same folder as youtube-dl.exe
Open a command prompt window and run there cmd /?. This command outputs the help for the Windows command processor. On last help page in last paragraph there is written which characters in a directory or file name or arguments of executables and scripts require the usage of double quotes: space and &()[]{}^=;!'+,`~
The character % has a special meaning in batch files as it marks the beginning and end of an immediately expanded environment variable reference or a batch file argument reference or a loop variable reference. The percent sign must be escaped with one more % to specify a literally interpreted % character.
In command prompt window run set and there are displayed the standard environment variables for the user account on the machine. One of those standard environment variables is USERPROFILE which holds the path to the current user's profile folder containing by default, for example, the subfolder Desktop.
Now let us look on the following line from your batch file:
youtube-dl.exe --extract-audio --audio-format mp3 --output C:\Users\*******\Desktop\(ext)s.%(ext)s %audio%
It would be good to use here a reference to the environment variable USERPROFILE for the Desktop directory. The user account name could contain a space character and therefore it is advisable to enclose the path in double quotes. Next there are parentheses and a single percent sign which definitely require double quotes and escaping the percent sign.
The URL stored in environment variable audio can't contain a space character as in URLs a space character must be encoded with %20. But this single percent sign causes again troubles on interpreting the line by Windows command processor. The solution is using delayed expansion.
Let us look on this batch code:
#echo off
setlocal EnableExtensions EnableDelayedExpansion
set "ToolPath=%~dp0"
cd /D "%USERPROFILE%\Desktop"
rem The directory may not exist. It would be a good idea to check that.
:audio
cls
echo/
echo/
echo Your audio will be downloaded and saved as a .mp3 format
echo/
echo/
set "audio="
:PromptUser
set /P "audio=Enter audio URL here: "
if not defined audio goto PromptUser
set "audio=!audio:"=!"
if not defined audio goto PromptUser
"%ToolPath%youtube-dl.exe" --extract-audio --audio-format mp3 --output "%USERPROFILE%\Desktop\(ext)s.%%(ext)s" "!audio!"
pause
cls
echo/
echo/
echo/
echo/
echo Your audio has now been downloaded.
%SystemRoot%\System32\ping.exe 127.0.0.1 -n 4 >nul
endlocal
The batch file first creates a local copy of all environment variables, enables command extensions and delayed variable expansion, and pushes also current working directory path on stack.
Next the path of the directory containing the batch file and the other executables used by this batch file is assigned to variable ToolPath. Run in command prompt window call /? for details on %~dp0 (drive and path of argument 0 – the batch file – always ending with a backslash).
Then the current directory is changed to the Desktop directory of the currently used user account independent from which drive the batch file was started. Run in command prompt window cd /? for details about this command and its options.
The line with youtube-dl.exe is changed as now the executable is called with full path (as current working directory is now the user's Desktop directory). Also the output directory is enclosed now in double quotes, uses also environment variable USERPROFILE, has escaped the single percent sign with one more % and the URL is referenced now in double quotes using delayed expansion (exclamation marks instead of percent signs). Run in a command prompt window set /? for help and details about delayed expansion.
For a timeout of 3 seconds the value used on command PING must be 4 as the first ping is always immediately successful.
The command ENDLOCAL results in discarding the local copy of the table with the environment variables (ToolPath is not defined anymore after this line and all changes on other variables are lost), restores previous values for delayed expansion (most likely turning it off as not enabled by default) and command extensions (most likely being still enabled as by default) and also restoring previous working directory (most likely the path of the batch file if started with a double click).
See also:
How does the Windows Command Interpreter (CMD.EXE) parse scripts?
DosTips forum topic: ECHO. FAILS to give text or blank line - Instead use ECHO/
How to stop Windows command interpreter from quitting batch file execution on an incorrect user input?
Path of user desktop in batch files
My requirement is - i need to read the filename from an input folder say - C:\Encrypt\In and pass it to the command java.exe -jar D:\SYS\src\PI\IN\Cryptage.jar -rc4 -crypt D:\SYS\src\PI\IN\Decrypt\ D:\src\PI\IN\Encrypt\ %VAR1%%VAR2%
i tried doing the one below - but no luck
set VAR1=FOR /R C:\Encrypt\In %F in (*.*) do echo %~nF
set VAR2=ABCD
echo %VAR1%%VAR2% (concatenate the filename with "ABCD" as constant)
java.exe -jar D:\SYS\src\PI\IN\Cryptage.jar -rc4 -crypt D:\SYS\src\PI\IN\Decrypt\ D:\src\PI\IN\Encrypt\ %VAR1%%VAR2%
(pass it here - so that each time a file comes in the input directory the variables can pick up the file names dynamically through the variables)
echo %VAR1%%VAR2% is not working.
Thanks anyway - i achieved it through this :- cd C:\Encrypt\In\ for %%f in (.) do ( rem echo %%~nfAPSI set v=%%~nfAPSI ) echo %v%
Here is a commented batch code for your task:
#echo off
set "ScanFolder=C:\Encrypt\In"
rem The loop runs command DIR to get a list of files with archive attribute set.
rem Directories are ignored even if archive attribute is set on a directory.
rem On each file with archive attribute currently set the archive attribute
rem is removed from file and then the command is started to process the file.
rem After all files with archive attribute were processed, the batch file
rem waits 5 seconds before scanning the folder again. The loop is infinite
rem and can be breaked only by pressing Ctrl+C or closing command prompt
rem window to stop command line interpreter.
:Loop
for /F "delims=" %%F in ('dir /AA-D /B "%ScanFolder%" 2^>nul') do (
%SystemRoot%\System32\attrib.exe -A "%ScanFolder%\%%~nxF"
java.exe -jar D:\SYS\src\PI\IN\Cryptage.jar -rc4 -crypt D:\SYS\src\PI\IN\Decrypt\ D:\src\PI\IN\Encrypt\ "%ScanFolder%\%%~nxF"
)
%SystemRoot%\System32\ping.exe -n 6 127.0.0.1>nul
goto Loop
java.exe should be called with full path enclosed in double quotes if possible as in this case command line interpreter would not always need to search for it in the folders of environment variable PATH.
Note: The batch file calls the new file with full path, file name and extension without anything appended. Of course you can replace %%~nxF at end of line calling java.exe also with %%~nFABCD if this is necessary in your environment.
For an explanation of the used commands and how they work in detail open a command prompt window and execute following commands to see the help of those commands:
attrib /?
dir /?
for /?
ping /?
I am trying to unzip some folders and then recombine them, however when I run the batch file it get the following error:
'unzip' is not recognized as an internal or external command,
operable program or batch file.
I am guessing I need to point the batch file to where 7-zip is correct? Any insight would be appreciated thanks!
See below for code:
#echo off
cls
:start
:unzip
echo.
echo Unzipping files
echo.
unzip ELMDB-85308-PI003_OVA_2of5.zip
unzip ELMDB-85308-PI003_OVA_3of5.zip
unzip ELMDB-85308-PI003_OVA_4of5.zip
unzip ELMDB-85308-PI003_OVA_5of5.zip
echo.
:combining
echo.
echo Combining parts
echo.
copy /b ELMDB-85308-PI003_OVA_1of4+ELMDB-85308-PI003_OVA_2of4+ELMDB-85308-PI003_OVA_3of4+ELMDB-85308-PI003_OVA_4of4 ELMDB-85308-PI003.OVA
:done
echo.
echo Done!
echo.
pause
:end
Instead of unzip as a command, try 7z -e.
If you copy 7z.exe to some directory that is on your PATH, then you don't need to specify the directory.
You can see your PATH by executing
PATH
from the prompt. This displays a ;-separated list of directories that are searched after the current directory) for executables.
If 7z.exe is not on your PATH, then you'd need
"c:\wherever\it is\7z" -e ....
(more explaining)
If 7z is in your path, then
7Z -e ELMDB-85308-PI003_OVA_2of5.zip
will unzip ELMDB-85308-PI003_OVA_2of5.zip
And you'd then need to add a line for each of the other files (which you have done).
If 7z.exe is not on your path then you need
"C:\Program Files\7-Zip\7z" -e ELMDB-85308-PI003_OVA_2of5.zip
and reproduce that for each of your files.
You can tell that 7z.exe is in your path by executing 7z from the prompt. You will get either a report stating that it's not recognised (ie it's not on your path) or you'll get a commands-and-switches help report (which means it is on your path)
Since the command 7z did not work, then it's not on your path, so you need the other form.
If you were to copy /b C:\Program Files\7-Zip\7z.exe"c:\windows\system32\" then in all probability you'd have 7z.exe on your path and hence you could use the short form.
I have a program in my FTP server to generate a file, which may take 3-5 minutes to complete and also I knew the name of the file which i being created by my program. Now, once I initiate the program in my server, I have keep checking until the file is created. Once it is created, I am using the below batch script to ftp the file to my local desktop.
#ftp -i -s:"%~f0"&GOTO:EOF
open 10.100.16.111
username
password
lcd c:\
cd root/output_folder
binary
mget "*partial_file_name*" REM mget using wildcard search
disconnect
bye
This script works fine for me. But the problem is, I need modify this script as such, script should keep running until the file is generated. Because i don't know when the file creation will get completed. So, it will great if some one help/guide me to make a looping script which will wait until the completion of file creation and download the same file through FTP.
With this edit you can launch the batch file with the file name on the command line, like this:
ftpscript.bat "filename.ext"
Note that your lcd uses c:\ which is a restricted location in later versions of windows.
#echo off
>file.tmp echo open 10.100.16.111
>>file.tmp echo username
>>file.tmp echo password
>>file.tmp echo lcd c:\
>>file.tmp echo cd root/output_folder
>>file.tmp echo binary
>>file.tmp echo mget "%~1"
>>file.tmp echo disconnect
>>file.tmp echo bye
:retry
ftp -i -s:"file.tmp"
if not exist "%~1" timeout /t 300 & goto :retry
echo file has downloaded
del file.tmp
pause
More elegant solution is to use an FTP client that supports parametrized scripts or commands on command-line, such as WinSCP, to avoid creating a temporary script file.
Parametrized script
The batch file would be more or less identical as with the Windows ftp:
#echo off
:retry
winscp.com /script=script.txt /parameter "%~1"
if not exist "%~1" timeout /t 300 & goto :retry
echo file has downloaded
pause
The ftp script converts to following WinSCP script:
open ftp://username:password#10.100.16.111/
lcd c:\
cd root/output_folder
get -transfer=binary "%1%"
exit
Commands on command-line
You can also inline the commands the to the batch file:
#echo off
:retry
winscp.com /command ^
"open ftp://username:password#10.100.16.111/" ^
"lcd c:\" ^
"cd root/output_folder" ^
"get -transfer=binary ""%~1""" ^
"exit"
if not exist "%~1" timeout /t 300 & goto :retry
echo file has downloaded
pause
References:
Automating file transfers to FTP server;
Upload to multiple servers / Parametrized script.
Had you ever need to upgrade to the FTPS or the SFTP, just modify the session URL in the open command command accordingly.
(I'm the author of WinSCP)