cmd throwing error when executing batch file - batch-file

I'm trying to connect to sqlplus using batch file. I have the following code. when i run the batch file the command prompt is throwing error "The filename, directory name, or volumen label syntax is incorrect.
but it is working fine in another machine. i can't understand the problem. the same is connecting when i type the commands in cmd directly without running batch file.
setlocal
set raaga=raaga1
set ORACLE_HOME=C:\Oracle\product\11.2.3\dbhome_1
set ORACLE_SID=%raaga%
set PATH=%ORACLE_HOME%\bin;%PATH%
(
Echo connect sys/manager22#%raaga% as SYSDBA;
) | Sqlplus /nolog
Do i need to install anything? any help is appreciated.
thanks in advance

Related

Execute a batch file from SQL server using xp_cmdshell

I have a .bat file that iterates through it's residing director and takes the file name and creates a series of insert into select openrowset statements that is written to another file for later use.
I am trying to execute this .bat file in SQL Server using the below statement:
EXEC master..xp_cmdshell 'cmd /c filepath\FileTransfers\incoming\pdfs\gensql.bat'
overall the command works, if I replace gensql.bat with helloworld.bat I get the expected output.
The problem:
When I attempt to execute the command using the gensql.bat I get null output and the file is not written to.
If I run the bat file from the command prompt it works as expected.
If I manually run the bat file from it's folder it works as expected.
If I attempt it to run it via PowerShell I get access denied as expected.
I have tried to run it using the SQL Server job agent and the job runs successfully but there the expected output to the file is not there.
The account I am logged into and running the bat file has the permissions to the file location because I load other files from the same file path.
Command I am executing in SQL Server
EXEC master..xp_cmdshell 'cmd /c filepath\FileTransfers\incoming\pdfs\gensql.bat'
Contents of .bat file -- all this bat file is doing is writing statements to a file
#echo off
echo. > loadFiles.sql
for /r %%i in (*.pdf) do (
echo INSERT INTO dbo.user_attachments(content, extension, recipient_id^)
echo SELECT bulkcolumn, '.pdf', '%%~ni'
echo FROM OPENROWSET(BULK '%%i', SINGLE_BLOB^) AS t;
) >> loadFiles.sql
Any help I can get with this is very much appreciated.

move command fails from batch file. But runs successfully when executed from command prompt

I have a simple move command as:
move tfa.war ..\..\..\tomcat\webapps
When i run this command in command prompt it works fine. But when i put this command in a batch file with variables like so, and execute the batch file in command prompt it fails with the message "The system cannot find the file specified".
cmd.exe /C webapp_deploy.bat tfa
And the contents of webapp_deploy.bat:
#ECHO OFF
set app_name=%~1
set webapps_directory=..\..\..\tomcat\webapps
move %app_name%.war %webapps_directory%
Any help would be much appreciated!

Václav Slavík's diff-pdf error message when running via batch file

Have you guys used Václav Slavík's diff-pdf?
I'm currently using it to automate pdf files comparison.. Because it's free and it outputs the result as a file. I needed to do it via batch file. This is my code so far:
#ECHO OFF
set /p i1=%1
set /p i2=%2
set /p i3=%3
c:\diff-pdf\diff-pdf --output-diff=i1 i2 i3
Running it from the batch file returns error message
What went wrong? Is it my code in batch file? I search through google, it seems correct.
I got it right now. Using this syntax:
#"C:\diff-pdf\diff-pdf.exe" "--output-diff=%~3" %1 %2
I edited my main batch file. And then I just called it from command prompt using this command line:
sample.bat file1.pdf file2.pdf c:\outputFolder\output.pdf
Thanks to #Mofi

Filezilla If statements

In the batch file segment I've posted I have an issue where I need to use filezilla and the command line to ensure that a scheduled script hasn't lost it's connection. My attempt was to use an if statement to verify the presence of a folder on the remote server, with the goal in mind that if there was no connection the file wouldn't be found and the program would exit immediately. The current batch file doesn't do this it instead continues on and may ultimately delete files whether or not they've been fixed. Any advice on both this file or an alternative method to accomplish the same thing would be greatly appreciated.
open xx.xx.xx.xx<br>
xxxxxxxx<br>
xxxxxxxx<br>
cd xxxxx<br>
! if exist xx.xx.xx.xx/xxxxxx/ (<br>
mput *.mp4<br>
)
! if not exist xx.xx.xx.xx/xxxxxxx (<br>
close<br>
)
! del *.mp4<br>
quit<br>
exit
In a batch command:
ping -n 1 ftp.server.com >nul || echo server is not responding

batch file to call an exe application

I have a script which I can run perfectly if I call it manually in the command prompt.
cd \
cd impressio
cd input
for %%f in (.txt)do (
echo "%%~nf"
"C:\Program Files\Splunk\bin\splunk cmd python" "D:impressio\deployment code\add_null.py" "%%~nf.txt" "%%~nf_processed.txt"
)
When I save this script as <filename>.bat and double-click, it always prompts me an error message: "Program Files is not recognized as an internal or external command".
Is it because of the environment variable setting issue? Did anyone come across such thing before, or does my code have a problem?
Not sure why Program Files is mentioned in the error message, but there does seem to be an issue with the line where you are calling your Python script.
In particular, this bit:
"C:\Program Files\Splunk\bin\splunk cmd python"
should likely be this instead:
"C:\Program Files\Splunk\bin\splunk" cmd python

Resources