Re: How to get a return code from an host command in SQL*Plus ?

From: Michel Cadot <micadot_at_netcourrier.com>
Date: 2000/05/04
Message-ID: <8errsg$17bh$1_at_news5.isdnet.net>#1/1


Marc,

Thanks for your answer.
That's a good idea. I have to slighty modify it:

SQL> var marc number
SQL> !ls fhfhfhh; echo exec :marc := $? >marc.sql fhfhfhh not found

SQL> _at_marc.sql

PL/SQL procedure successfully completed.

SQL> print marc

      MARC


         2

This works well in Unix but actually i have to do that on NT and it seems that neither chaining the commands nor %errorlevel% (the same as $?) is recognized in SQL*Plus/NT:

SQL>var marc number
SQL>host dir ggggg.hhh; echo exec :marc := %errorlevel% >marc.sql Fichier introuvable

SQL>host type marc.sql
 Le volume dans le lecteur C s'appelle PC20941  Le numéro de série du volume est 7808-5A6A

Répertoire de C:\

Répertoire de C:\

Répertoire de C:\

Répertoire de C:\

SQL>host echo %errorlevel% >tmp.txt

SQL>host type tmp.txt
Le fichier spécifié est introuvable.

SQL>host type marc.sql; host type tmp.txt

marc.sql

 Le volume dans le lecteur C s'appelle PC20941  Le numéro de série du volume est 7808-5A6A

Répertoire de C:\

Répertoire de C:\

Répertoire de C:\

Répertoire de C:\

Le fichier spécifié est introuvable.
Une erreur est survenue lors du traitement de : host. Le fichier spécifié est introuvable.
Une erreur est survenue lors du traitement de : type. Le fichier spécifié est introuvable.
Une erreur est survenue lors du traitement de : tmp.txt.

Can you or anyone else help me?

--
Regards
Michel


<marcpark_at_my-deja.com> a écrit dans le message : 8epftt$574$1_at_nnrp1.deja.com...

> Yes, it is possible to get the return code form a host command
> An example in unix
> variable marc number
> !ls ajdadfaldjfl; echo select $? into marc from dual > marc_select.sql
> !echo "/" >> marc_select.sql
> _at_marc_select
> Which would return 2 into the bind varaible marc.
>
> Then create a pl/sql script.
> You look at the bind_variable and determine if to continue
> or not.
> declare
>
> begin
> IF :marc = 0 THEN
> update emp set ...
> END IF
> END;
>
> This is not trivial and would need more word to ensure it works,
> but the general concept is there
>
> Marc Parkinson
> Oracle Developer
>
>
>
> In article <8ep751$2vca$1_at_news4.isdnet.net>,
> "Michel Cadot" <micadot_at_netcourrier.com> wrote:
> >
> > In a SQL*Plus script, i have to launch an host command,
> > then test its return code and go on with the SQL script
> > only if it is 0.
> >
> > How to get and test this return code?
> >
> > Example:
> > SQL> select * from emp where ...;
> > SQL> host myProg
> > SQL> if myProg return code is not 0 exit <-- Can i do this and how?
> > SQL> update emp set ...
> >
> > --
> > Thanks
> > Michel
> >
> >
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
Received on Thu May 04 2000 - 00:00:00 CEST

Original text of this message