Interactive format IN BATCH FILE CALLING SQL QUERY
Hi,
Below code i have written to get some data from file test.txt and O/P the data from database. For this i m running MS-DOS batch file which is calling test.sql and which in turn calls the file test.sql and get desired result from database. The below script works perfectly
What i want is the more interactive format and not hard coded format esp location and name of the TEXT FILE . How i can make changes that whenever BATCH FILE is run, it ask for file name and location and then passes those information to SQL FILE which in turn fetches the results from database
BATCH FILE : test.bat
sqlplus sys/xxxxx as sysdba @test.sqlSQL FILE: test.sql
SET SERVEROUTPUT ON
DECLARE
lc_file_handle UTL_FILE.file_type;
lc_file_dir VARCHAR2 (100);
lc_file_name VARCHAR2 (50);
data VARCHAR2 (500);
v1 ECCSYS.hwcontainer.hwcontainerserialnumber%type;
v2 ECCSYS.storagedevice.devicename%type;
s2 ECCSYS.storagedevice.isreserved%type;
BEGIN
lc_file_dir := 'DATA_PUMP_DIR';
lc_file_name := 'test.txt';
lc_file_handle := UTL_FILE.fopen (lc_file_dir, lc_file_name, 'R');
LOOP
BEGIN
UTL_FILE.get_line (lc_file_handle, data);
v1 := SUBSTR (data,1,INSTR (data, ',', 1) - 1);
v2 := substr(data, INSTR (data, ',', 1, 1) + 1, length(data) - INSTR (data,',', 1, 1));
select isreserved into s2 from ECCSYS.storagedevice where devicename=v2 and storagearrayid = (select hwcontainerid from ECCSYS.hwcontainer where hwcontainerserialnumber =v1);
DBMS_OUTPUT.PUT_LINE(v1 ||' '|| v2 ||' '|| s2);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
EXIT;
END;
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
UTL_FILE.fclose (lc_file_handle);
END;
EXIT;TEXT FILE : test.txt
000190300153,170
000190300153,171
Hi,
I have made some changes in the batch and sql file but problem is , still test.sql is seeking name of the file even though its passed from batch file to sql file.
BATCH FILE : test.bat
@echo off
set /P id=Enter THE FILE NAME: %=%
echo %id%
sqlplus sys/xxxx as sysdba @test.sql %idSQL FILE : test.sql
SET SERVEROUTPUT ON
DECLARE
lc_file_handle UTL_FILE.file_type;
lc_file_dir VARCHAR2 (100);
lc_file_name VARCHAR2 (50);
data VARCHAR2 (500);
v1 ECCSYS.hwcontainer.hwcontainerserialnumber%type;
v2 ECCSYS.storagedevice.devicename%type;
s2 ECCSYS.storagedevice.isreserved%type;
BEGIN
lc_file_dir := 'DATA_PUMP_DIR';
lc_file_name := '&id';
lc_file_handle := UTL_FILE.fopen (lc_file_dir, lc_file_name, 'R');
LOOP
BEGIN
UTL_FILE.get_line (lc_file_handle, data);
v1 := SUBSTR (data,1,INSTR (data, ',', 1) - 1);
v2 := substr(data, INSTR (data, ',', 1, 1) + 1, length(data) - INSTR (data,',', 1, 1));
select isreserved into s2 from ECCSYS.storagedevice where devicename=v2 and storagearrayid = (select hwcontainerid from ECCSYS.hwcontainer where hwcontainerserialnumber =v1);
DBMS_OUTPUT.PUT_LINE(v1 ||' '|| v2 ||' '|| s2);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
EXIT;
END;
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
UTL_FILE.fclose (lc_file_handle);
END;
EXIT;
Similar Messages
-
Calling a batch file in sql scripts
Hi friends,
I am looking for a way to call any batch file in sql scripts.I am avoiding to use DBMS_SCHEDULER package because my application server and database server are diifferent .
I am using the sql script in application server.plz help.<ironic>
Ah, I see. This of course explains everything.
</ironic>
Now to be serious: there is no way to run a batch script from SQL. The tools which submit SQL Statements to the database are often capable of doing so; host in SQL*Plus can issue OS commands, the host builtin in Forms does it too, and with dbms_scheduler you can run a shell script on the database server.
So depending on the tools you are using there are several ways to run OS commands. So far you didn't tell us what you want to do with what tools in which version you want to do it. So to only answer is: this is not possible. You cannot run a batch script from plain SQL.
cheers -
Executing the batch file from SQL Server Agent job
Hi - I have a simple batch file (.bat) which connects the SFTP server and drop the files to location machine. When I run the .bat file manually its working fine but when I schedule it in SQL Agent its keep on running and never shows success message.
Could you please tell me how can i resolve it. Its very urgent for me.
thanksIf you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n) Remote working directory is /
When you connect via putty you get prompted to accept a key in interactive mode. At this point your batch file is waiting for someone to type in y or n.
Try running putty in batch mode to get around this.
http://the.earth.li/~sgtatham/putty/0.52/htmldoc/Chapter6.html#6.1.8
6.1.8 -batch: avoid interactive prompts
If you use the -batch option, PSFTP will never give an interactive prompt while establishing the connection. If the server's host key
is invalid, for example (see section 2.2), then the connection will simply be abandoned instead of asking you what to do next.
This may help PSFTP's behaviour when it is used in automated scripts: using -batch, if something goes wrong at connection time, the batch
job will fail rather than hang. -
Generate PDF file from sql query
I have a table having some now i want to perform some calculation on tht data and then want to export it into a
pdf file.
All this thing thing i want to write in a sql query so tht i can put it in a stored procedure .
Kindly suggest.timberwoods,
One way is to use SSRS. You may embed a query and it generates the report which you can always download as pdf, excel etc. Look up on the net for this - that shud probably solve your requirement!!
If not, found this at codeproject - allows you to generate pdfs - again using SSRS !
http://www.codeproject.com/Articles/19236/Create-data-driven-PDF-on-the-fly-by-using-SQL-ser
http://www.sqlservercentral.com/articles/Miscellaneous/creatingapdffromastoredprocedure/1104/
Thanks,
Jay
<If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'> -
I am not able to see the trace files for SQL query
Hello, I am using windows vista OS.
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
SQL>
I enabled the trace as below
alter system set timed_statistics=TRUE
alter system set sql_trace=TRUE
After this, I ran sql query from scott as below.
select count(*) from emp;
After this, i checked in user dump directory. The trace files are generating... But this sql code is not appearing in the trace files...
Am i missing anything... Any help is appreciated.
ThanksThis may happen when the trace file is not completely closed.You may try again doing like this,
alter session set sql_trace=true;
select * from emp;
alter session set sql_trace=false;After this,disconnect and exit from your session as well. This should close the file completely and you should be able to see your command in it.
HTH
Aman.... -
View calling SQL query in procedure
Hi,
is it possible to see in SQL procedure the SQL query, which calls this procedure? I want to log that SQL when some error occurs.
Thanks
SASAI'll be interested to see if anyone has an easy solution to this. Here's a function that will get all the currently open cursors but that's not quite the solution ...
create or replace function f
return varchar2 is
v_sql_text varchar2(32767);
begin
for rec in (
select v$sqltext_with_newlines.sql_text
into v_sql_text
from v$open_cursor,
v$sqltext_with_newlines
where v$open_cursor.address = v$sqltext_with_newlines.address
and v$open_cursor.hash_value = v$sqltext_with_newlines.hash_value
and v$open_cursor.sid = (
select sid
from v$mystat
where rownum = 1)
and (v$open_cursor.address, v$open_cursor.hash_value) != (
select sql_address,
sql_hash_value
from v$session
where sid = (
select sid
from v$mystat
where rownum = 1))
order by v$sqltext_with_newlines.address,
v$sqltext_with_newlines.piece
) loop
v_sql_text := v_sql_text || rec.sql_text;
end loop;
return v_sql_text;
end; -
Execute java class from a batch file called from runtime.exec
Hi.
I don´t know if this question fits here.
I wan´t to execute a batch file (on Win XP) with runtime.exec. That batch file will execute another java program.
I have the following code:
Resolutor.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class Resolutor {
* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
Runtime r = Runtime.getRuntime();
//String[] command = { "cmd.exe", "/C",".\\lanzar.bat .\\ .\\ 001.res:001.dtt" };
String[] command = { "cmd.exe", "/C",".\\tarea\\lanzar.bat " + args[0] + " " + args[1] + " " + args[2]};
try {
//Process proceso = Runtime.getRuntime().exec("lanzar.bat");
Process proceso = Runtime.getRuntime().exec(command);
InputStream stderr = proceso.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
System.out.println("<ERROR>");
while ( (line = br.readLine()) != null)
System.out.println(line);
System.out.println("</ERROR>");
int exitVal = proceso.waitFor();
System.out.println("EXITVAL: " + exitVal);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}lanzar.bat
java Lanzador %1 %2 %3Lanzador.java
import java.util.Vector;
public class Lanzador {
* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
Repetitiva rpt=new Repetitiva();
String rutaFicheros=args[0];
String rutaResultado=args[1];
String[] ficheros=args[2].split(":");
Vector<String> ficheroDatos=new Vector<String>();
for(int i=0;i<ficheros.length;i++){
ficheroDatos.add(ficheros);
System.out.println(ficheros[i]);
System.out.println("RUTA DE FICHEROS: " + rutaFicheros);
System.out.println("RUTA DE RESULTADOS: " + rutaResultado);
System.out.println("CALCULAR");
rpt.setRepetitiva(ficheroDatos, rutaFicheros, rutaResultado);
rpt.calcular();
}I´ve got Resolutor.class in /res and the other two files (and the rest of the files for running) in /res/tarea.
If I execute /res/tarea/lanzar.bat from the command line everything works fine, it calls java and runs lanzador without problem.
The problem comes when I try to execute the batch file via Resolutor.class. It executes the batch file without problem, but it throws a *java.lang.NoClassDefFoundError: Lanzador* when launching the new java application.
Any ideas of how can I solve that problem. (It must do it via batch file).Well, I tried putting in the bat file java -classpath .\tarea Lanzador %1 %2 %3 and didn´t work.
I ve tried the bat modification, and the directory in x.txt is k:\res instead of k:\res\tarea.
I´ve tried to modifiy it to java .\tarea\Lanzador and didn´t work so I have put a cd like the following and it appears to work.
cd tarea
java Lanzador %1 %2 %3Thanks for the replies. -
I have created XML File from Query using below function:-
select dbms_xmlgen.getxml('
select * from tblreports where rownum<=1') from dual;
"(CLOB) <?xml version="1.0"?>
<ROWSET>
<ROW>
<REPORTID>preRES0011</REPORTID>
<ALIAS>Date wise Summary of pins Report</ALIAS>
<ACTIVE>Y</ACTIVE>
<TITLE>Date wise Summary of pins Report</TITLE>
<QUERY>select tsb.month1,
count(SIDNUMBER)GENERATED,
sum(case WHEN SERIALSTATUSID='SRS01' THEN 1 ELSE 0 END)NotAllocated,
SUM(CASE WHEN SERIALSTATUSID='SRS02' or SERIALSTATUSID='SRS03' or SERIALSTATUSID='SRS05' THEN 1 ELSE 0 END)ALLOCATED,
SUM(CASE WHEN SERIALSTATUSID='SRS02' or SERIALSTATUSID='SRS01' THEN 1 ELSE 0 END)NOTASSIGNEDTORESELLER,
SUM(CASE WHEN SERIALSTATUSID='SRS03' THEN 1 ELSE 0 END)READYTOACTIVATE,
sum(CASE WHEN SERIALSTATUSID='SRS05' THEN 1 ELSE 0 END)ACTIVATED,
sum(CASE WHEN SERIALSTATUSID='SRS06' THEN 1 ELSE 0 END)Terminated,
sum(CASE WHEN SCRAPSTATUSID='CST01' THEN 1 ELSE 0 END)scraped,
sum(CASE WHEN LOCKSTATUSID='CST01' THEN 1 ELSE 0 END)locked,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
from (SELECT TO_CHAR(CREATEDATE,'DD-MON-YYYY')MONTH1 ,PINUSAGEMODEID,SERIALBATCHID,SERIALIDCOUNT,CREATEDATE FROM TBLMSERIALBATCH )TSB,
tblmserial ts
where TSB.SERIALBATCHID=ts.SERIALBATCHID
and to_char(TSB.CREATEDATE,'MON-YYYY')='$1'
GROUP BY TSB.MONTH1
order by TO_DATE(MONTH1,'dd-mon-yyyy') DESC</QUERY>
<CONNECTIVITYID>C0001</CONNECTIVITYID>
<INPUTREQUIRED>Y</INPUTREQUIRED>
<INPUTNAME>Month</INPUTNAME>
<CREATEDATE>30-JAN-10</CREATEDATE>
<LASTMODIFIEDDATE>22-FEB-10</LASTMODIFIEDDATE>
<CREATEDBY>reportadmin</CREATEDBY>
<LASTMODIFIEDBY>reportadmin</LASTMODIFIEDBY>
<TITLEPARAM>Y</TITLEPARAM>
<SUBTITLE>Date wise Summary of pins Report For &1</SUBTITLE>
<ELEMENTTYPEID>AET002</ELEMENTTYPEID>
<REPORTTYPEID>RTP01</REPORTTYPEID>
<SORTFIELD>Disable</SORTFIELD>
</ROW>
</ROWSET>
But in that it is taking ''' for ' ' instead of '$1' it is taking '$1'
how to keep ' ' in XML file instead of &apos?You can use bcp with query out option
use your above query as the source query and use queryout option after specifying destination as your required local file path (specify extension as .xml)
see
http://visakhm.blogspot.com/2013/10/bcp-out-custom-format-data-to-flat-file.html
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Can we store procedure in a folder in text file using SQL QUERY
I want to create a folder in D drive and give folder name as current date. After that create no. of text files based on how many procedure are, text file name will be same as procedures name and insert a procedures inside the text files by using stored
procedure.I want to create a folder in D drive and give folder name as current date. After that create no. of text files based on how many procedure are, text file name will be same as procedures name and insert a procedures inside the text files by using stored
procedure.
You can use generate scripts wizard for this. It will by default give scripts in .sql format. You can then use a command line script to change all of them to .txt.
Another option is to have SSIS package and use File SYstem Task to rename it to .txt
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
How to make an XML file from SQL query on local disc (c:\temp)?
This query shows me XML results, but can I somehow make an XML file to local disc?
Thanks.
DECLARE @IMO NUMERIC(8,0)
DECLARE @Counter INT
SELECT @Counter = 1
WHILE ( @Counter <15 )
BEGIN
SET @IMO = (SELECT ImoNo from Vessel where ID=@Counter)
SELECT top 1
@IMO as ImoNumber,
VesselName,
Time,
lat as CurrentLatitude,
lon as CurrentLongitude,
sog as SpeedOverGround,
cog as CourseOverGround,
hdg as HeadingInDegrees,
GoingToCountry = (SELECT TOP 1 CountryName
FROM ShipSchedule
WHERE ImoNo = @IMO and DestPosArrived = 'false'
ORDER BY DestPosETA ),
GoingToHarbour = (SELECT TOP 1 Harbour
FROM ShipSchedule
WHERE ImoNo = @IMO and DestPosArrived = 'false'
ORDER BY DestPosETA ),
DestinationLatitude = (SELECT TOP 1 DestPosLAT
FROM ShipSchedule
WHERE ImoNo = @IMO and DestPosArrived = 'false'
ORDER BY DestPosETA ) ,
DestinationLongitude = (SELECT TOP 1 DestPosLON
FROM ShipSchedule
WHERE ImoNo = @IMO and DestPosArrived = 'false'
ORDER BY DestPosETA ),
ArrivalTime = (SELECT TOP 1 DestPosETA
FROM ShipSchedule
WHERE ImoNo = @IMO and DestPosArrived = 'false'
ORDER BY DestPosETA ),
GoingFromCountry = (SELECT TOP 1 CountryName
FROM ShipSchedule
WHERE ImoNo = @IMO and DestPosArrived = 'true'
ORDER BY DestPosETA desc),
GoingFromHarbour = (SELECT TOP 1 Harbour
FROM ShipSchedule
WHERE ImoNo = @IMO and DestPosArrived = 'true'
ORDER BY DestPosETA desc),
DepartureTime = (SELECT TOP 1 DestPosETD
FROM ShipSchedule
WHERE ImoNo = @IMO and DestPosArrived = 'true'
ORDER BY DestPosETA desc)
FROM Position
WHERE ImoNo = @IMO
order by time desc
for Xml AUTO,elements,root('SplosnaPlovba')
SELECT @Counter = @Counter + 1
ENDYou can use bcp with query out option
use your above query as the source query and use queryout option after specifying destination as your required local file path (specify extension as .xml)
see
http://visakhm.blogspot.com/2013/10/bcp-out-custom-format-data-to-flat-file.html
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Create batch file containing SQL commands
Hi,
Iam using windows xp... I have 8 *.sql files, all of them contain insert statements and every file takes 40 min to execute and when one finishes i execute the other.
Is there any way that i can combine them and execute at one go..
Now iam using
spool o:\abc.log
@abc.sql
spool off
Can any one help me ..
Any help would be appreciated
Thanks> all of them contain insert statements and every file takes 40 min to execute
Insert statements!?
All of them totally trash the Oracle Shared Pool.. If only done properly, each would take mere seconds to run and not 40 minutes.
A snip of a benchmark I posted some time ago showing just how utterly wrong it is to code SQL inserts using literal values.
SQL> create table footab( n number );
Table created.
SQL> set timing on
SQL>
SQL> -- doing a 100,000 inserts using a single SQL INSERT with bind variable
SQL> declare
2 sqlInsert varchar2(1000);
3 begin
4 sqlInsert := 'insert into footab( n ) values( :0 )';
5 for i in 1..100000
6 loop
7 execute immediate sqlInsert using i;
8 end loop;
9 end;
10 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:04.91
SQL> -- doing a 100,000 inserts using a 100,000 SQL INSERTs
SQL> declare
2 sqlInsert varchar2(1000);
3 begin
4 -- need to built a unique SQL for each insert
5 for i in 1..100000
6 loop
7 sqlInsert := 'insert into footab( n ) values( '||i||' )';
8 execute immediate sqlInsert;
9 end loop;
10 end;
11 /
PL/SQL procedure successfully completed.
Elapsed: 00:05:21.47
SQL>The second method is what you are using. 1000's of insert statements, each with hard coded literal values to insert.
The first method show how it should be done from the client side - using a single SQL insert with bind variables.
And the result? 5 minutes 21 seconds versus a mere 4.91 seconds!!!
You need to seriously rethink your approach. Abusing Oracle is not how one achieve the spectacular performance and scalability that Oracle is famous for. -
Oracle 11g on CITRIX ( windows 2008 R2 ) OS batch file call fails
Hello Sir/Madam,
I've been using HOST built-in to invoke a command window to call another application from my oracle application form. The application is GFS Forms 6i on Oracle 11g db w/ XP OS. This logic works.
--XP OS logic:
declare
cmd varchar2(200);
url varchar2(200) := 'C:\PROGRA~1\ADVANT~1\GFS\start_grids_with_coords_pd.bat';
location1 varchar2(100);
location2 varchar2(100);
begin
go_block('GAS_SERVICES');
location1 := substr(:gas_services.location_coord, 1, 5);
location2 := substr(:gas_services.location_coord, 6, 5);
tool_env.getvar('comspec', cmd);
host('cmd /c start '||url ||' '||location1||' '||location2);
end;
Now, we are upgrading to W7 OS also, we would like use this function on CITRIX ( Windows server 2008 R2 ) server. For some reason, we are encountering errors when tilda /( squiggly ) line is used or a double quote
-- CITRIX/W7 logic:
declare
cmd varchar2(200);
url varchar2(200) := 'C:\PROGRA~2\ADVANT~1\GFS\start_grids_with_coords_pd.bat';
location1 varchar2(100);
location2 varchar2(100);
begin
go_block('GAS_SERVICES');
location1 := substr(:gas_services.location_coord, 1, 5);
location2 := substr(:gas_services.location_coord, 6, 5);
tool_env.getvar('comspec', cmd);
host('cmd /c start '||url ||' '||location1||' '||location2);
end;
I'll appreciate your help!
Regards,
Vani Sonti
Edited by: user11141511 on May 21, 2013 1:46 PMHello,
Have you tried using long filename instead of short filename ? When using long filename, you need to enclose it with double quotes.
Exemple :
url varchar2(200) := 'C:\PROGRA~1\ADVANT~1\GFS\start_grids_with_coords_pd.bat';
become
url varchar2(200) := 'C:\PROGRAM FILES\ADVANT_WHATEVER HERE\GFS\start_grids_with_coords_pd.bat';
and
host('cmd /c start '||url ||' '||location1||' '||location2);
become
host('cmd /c start '|| chr(34) || url || chr(34) || ' '||location1||' '||location2);
This work fines with Forms 6i on Windows 2003 and Citrix, but didn't try on Windows 2008. -
Batch file to query an IP address and amend it
Iain Smart wrote:So a client can have an IP address from any of 4 subnets?Do you have routing between the various subnets? Otherwise how do the clients connect to other internal resources (server, printers etc) that may be on another subnet?It sounds like you need to have some form of failover at the router rather than switching IP address at the client.This way you can leave the internal IP range and the router handles the multiple connections.However, you can use this command to change the IP address (needs admin priviledges):
Batchfilenetsh interface ip set address name=”Local Area Connection” staticHi Guys,Right, I need to create a batch file which will query the LAN IP address then display what connection it is connected to.So, at one of our sites we have multiple internet connections due to it being in the middle of nowhere and the internet connections are very unstable.We have 2 ADSL connections and 2 4G/3G/2G connections which are all on the same LAN but are seperated by different subnetsSo I need the script to check the IP address and display whether it is on Connection A, B, C or DI will then need the script to ask the user which connection they would like to be on and then it will change the IP to fit the criteria of the subnet they wantThe DNS addresses stay the sameOh and this script will be ran on many different PCs so it needs to check the Local Area Connection and amend it current IP. for example:192.168.3.1 -...
This topic first appeared in the Spiceworks Community -
I've been having a lot of problems trying to get an old batch file we have laying around, to run from my powershell script. The batch file actually asks for two inputs from the user. I've managed to put together a powershell that echos a response, but of
course, that only will answer one of the prompts. As usual, I've simplified things here to get my testing done. The batch file looks like this:
@ECHO OFF
SET /P CUSTID=Customer Number:
SET /P DBCOUNT=Number of Live Databases:
ECHO Customer Id was set to : %CUSTID%
ECHO Database Count was set to : %DBCOUNT%
Two inputs, two echos to verify values have been set. Now, the powershell looks like this:
Param(
[string]$ClientADG,
[string]$ClientDBCount,
[scriptblock]$Command
$ClientADG = '1013'
$ClientDBCount = '2'
$Response = $ClientADG + "`r`n" + $ClientDBCount
$Command = 'Invoke-Command -ComputerName localhost -ScriptBlock {cmd /c "echo ' + $ClientADG + ' | E:\Scripts\Setup\Company\DatabaseSetupTest.bat"}'
powershell -command $Command
Output looks like:
Customer Number: Number of Live Databases: Customer Id was set to : 1013
Database Count was set to :
As expected, as I'm only passing in one value. I can't figure out how to get a second value passed in for the second prompt. Instead of $ClientADG, I tried to mash the two value together in the $Response variable with a cr/lf or a cr or a lf in between,
but no go there either. The first input gets set to the second value, and second input is blank still. In the essence of time, I need to get this batch file called from Powershell to get some folks productive while I actually rewrite what the batch file does
in another powershell, so it can be integrated into other things. (I'm automating what a bunch of people spend hours doing into multiple scripts and eventually one BIG script so they can focus on doing their real jobs instead).
How do I get this right in powershell? I don't want to modify the batch file at all at this point, just get it running from the powershell.
Thanks in advance!
mpleafIt's a "simple" test so I can figure out how to get the arguments passed from ps to bat. The bat file looks like this:
@ECHO OFF
SET CUSTID = %1
SET DBCOUNT = %2
ECHO Customer Id was set to : %CUSTID%
ECHO Database Count was set to : %DBCOUNT%
That's it. The PS script looks like this:
Invoke-Command-ComputerName myserver-ScriptBlock{cmd/c"E:\Scripts\Setup\Company\DatabaseSetupTest.bat
1013 2"}
That's it. The bat file exists on "myserver", and I'm getting the echo back, but without the values.
mpleaf -
Query regarding running Java application from Batch file
Hi,
I have written an application in Java and I have packaged it as a JAR file.
In my system I use a batch file called 'run.bat' to execute the program. The batch file is as follows:
java -classpath "%CLASSPATH%;editor.jar" editor.JPad
This works fine in my system. But when it is executed in other systems where JRE is not configured properly, I am not able to correctly start the Java application.
Please can anybody tell me, how to detect the JRE from the Batch file and refer to it correctly, so that it will run in any system with JRE.
Can we do this from a Batch file ?
Hoping for a quick reply.
Thanks,
S.SampathYou can't really "detect" whether a JRE is available from a batch. All I can think of is to check for the typical Java variables (JVM_HOME, CLASSPATH etc) to exist. If they don't, especially JVM_HOME, a JRE is probably not installed.
Maybe you are looking for
-
Hello: I have JWS app I've been working on for a long time. I just added JavaHelp to it. I got it all working nicely on my local machine. When I went to deploy in JWS, I ran into a permission problem. JavaHelp is included as an extension, and I've se
-
Hi can i use xp recovery disk for dv2000 to downgrade a dv2000 with vista pre installed thanks
Hi i have 2 dv2000 laptops with different model no,s one with xp factory fitted and one with vista factory fitted can i use the xp recovery disks from the xp laptop to downgrade the vista to xp or is it better to install windows 7 please many tha
-
Cannot open itunes after download
I just bought my nano ipod. i downloaded everything as instructed;however, when i clicked on the itunes icon to open it--the agreement consent form pops up and disappears before i can click anything! also, the quicktime player pops up and then dissap
-
3D bar chart, color by height of bar
<p>I would like to create a 3D bar chart where the color of the bar depends on the height of the bar. Has anybody done this with CR?</p><p>Bob.</p>
-
X,Y Scatter Plot Problem
Is there any way to change the huge symbols in an x,y plot? All I want are dots not huge X's, O's, etc., and I want to be able to connect the dots. Plus, hopefully in the future, I would also like to be able to fit a curve to the data points. For now