Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

using here strings for command input

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 05-10-2008   #1 (permalink)
steve
Guest


 

using here strings for command input

i just downloaded powershell as i'm trying to migrate a bash script to a
Windows compatible scripting language.my script used to connect to an oracle
database and used heredocuments ( here strings) for this goal as follows

sqlplus -L user/passwd << EOF
oracle sqlplus commands go here
EOF

trying the same thing with power shell
sqlplus -L user/passwd @'
Quote:
Quote:

>>some commands
>>'@
>>
would not work because the '@' symbol has another meaning for sqlplus.
i'm wondering if there's analternative for '@' that would do the same job
like for ex

sqlplus -L user/passwd $'
Quote:
Quote:

>>some commands
>>'$
>>


My System SpecsSystem Spec
Old 05-10-2008   #2 (permalink)
Bob Landau
Guest


 

RE: using here strings for command input

Steve,

The problem your having is you've not created a here-string.

instead of this
Quote:

> sqlplus -L user/passwd @'
Quote:
Quote:

> >>some commands
> >>'@

use this

@'
sqlplus -L user/passwd
some commands
'@

To signal to Powershell you are passing a here-string the @<qoute> must be
on a line by itself likewise for the <quote>@

Having said that verify you can get the "stuff within the here-string to
work correctly at the command line prior to putting it in one.

"steve" wrote:
Quote:

> i just downloaded powershell as i'm trying to migrate a bash script to a
> Windows compatible scripting language.my script used to connect to an oracle
> database and used heredocuments ( here strings) for this goal as follows
>
> sqlplus -L user/passwd << EOF
> oracle sqlplus commands go here
> EOF
>
> trying the same thing with power shell
> sqlplus -L user/passwd @'
Quote:
Quote:

> >>some commands
> >>'@
> >>
> would not work because the '@' symbol has another meaning for sqlplus.
> i'm wondering if there's analternative for '@' that would do the same job
> like for ex
>
> sqlplus -L user/passwd $'
Quote:
Quote:

> >>some commands
> >>'$
> >>
>
>
My System SpecsSystem Spec
Old 05-10-2008   #3 (permalink)
steve
Guest


 

Re: using here strings for command input


k guys , first let me thank you for the answers
to start with Bob's answer, i tried your idea and it seems that power shell
is just "swallowing" sqlplus coz i only get back the commands i typed between
the @'.. '@.
say
@'
Quote:
Quote:

>>sqlplus user/passwd
>>drop table test;
>> create table test(test varchar2(100);
>>exit;
>>'@
>>
sqlplus user/passwd
drop table test;
create table test(test varchar2(100);
exit;

i checked the database and nothing is executed !
if your familiar with UNIX/Linux, you can have your program(not just
sqlplus) grab the input ( the commands) from the shell using the syntax i
showed you above - it's actually a kind of redirection '<<', your program
will be reading those commands .thus when your shell script runs all that
comes between @'..'@ is executed by the program not the shell. that's the
behavior i'm seeking.
and Shay, escaping the @ might clear things up for PS but not for sqlplus
since @ has a special meaning for sqlplus, it instructs it that whatever
follows '@' is an sql script relative-or-absolute path and it has to execute
it so simply escaping '@' with something has no meaning for it.

i assume this does not exist in windows just yet.
"Shay Levi" wrote:
Quote:

>
> You can escape it with a backtick `@
>
> get more info:
>
> help about_Escape_character
>
> ---
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

> > i just downloaded powershell as i'm trying to migrate a bash script
> > to a Windows compatible scripting language.my script used to connect
> > to an oracle database and used heredocuments ( here strings) for this
> > goal as follows
> >
> > sqlplus -L user/passwd << EOF
> > oracle sqlplus commands go here
> > EOF
> > trying the same thing with power shell sqlplus -L user/passwd @'
> >
Quote:

> >>> some commands
> >>> '@
> > would not work because the '@' symbol has another meaning for sqlplus.
> > i'm wondering if there's analternative for '@' that would do the same
> > job
> > like for ex
> > sqlplus -L user/passwd $'
> >
Quote:

> >>> some commands
> >>> '$
>
>
>
My System SpecsSystem Spec
Old 05-10-2008   #4 (permalink)
Shay Levi
Guest


 

Re: using here strings for command input


You can escape it with a backtick `@

get more info:

help about_Escape_character

---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> i just downloaded powershell as i'm trying to migrate a bash script
> to a Windows compatible scripting language.my script used to connect
> to an oracle database and used heredocuments ( here strings) for this
> goal as follows
>
> sqlplus -L user/passwd << EOF
> oracle sqlplus commands go here
> EOF
> trying the same thing with power shell sqlplus -L user/passwd @'
>
Quote:
Quote:

>>> some commands
>>> '@
> would not work because the '@' symbol has another meaning for sqlplus.
> i'm wondering if there's analternative for '@' that would do the same
> job
> like for ex
> sqlplus -L user/passwd $'
>
Quote:
Quote:

>>> some commands
>>> '$

My System SpecsSystem Spec
Old 05-10-2008   #5 (permalink)
Keith Hill [MVP]
Guest


 

Re: using here strings for command input

"steve" <steve@xxxxxx> wrote in message
news:8C2F5934-6438-4E5D-B9FC-EEACBB187A03@xxxxxx
Quote:

> i just downloaded powershell as i'm trying to migrate a bash script to a
> Windows compatible scripting language.my script used to connect to an
> oracle
> database and used heredocuments ( here strings) for this goal as follows
>
> sqlplus -L user/passwd << EOF
> oracle sqlplus commands go here
> EOF
>
> trying the same thing with power shell
> sqlplus -L user/passwd @'
Quote:
Quote:

>>>some commands
>>>'@
>>>
> would not work because the '@' symbol has another meaning for sqlplus.
Yes but SQL doesn't ever see the @ since Powershell parses it e.g.:

7> echoargs -L user/passwd @'
Quote:
Quote:

>> some commands
>> some more commands
>> and some more commands
>> '@
>>
Arg 0 is <-L>
Arg 1 is <user/passwd>
Arg 2 is <some commands
some more commands
and some more commands>

Note: echoargs is a utility in the PowerShell community extensions
(http://www.codeplex.com/powershellcx).

Could it be that the newlines in the here string are throwing off sqlplus?

--
Keith

My System SpecsSystem Spec
Old 05-10-2008   #6 (permalink)
Bob Landau
Guest


 

Re: using here strings for command input

Steve I've not see you directly answer whether you are able in powershell
from the same directory able to execute the comands within the here-string.

PowerShell unlike many shells does not let you execute commands that are not
at least partially qualified. i.e.
Quote:

>: blaa will not work unless the directory which foo lives in is in the "path" environment
Quote:

>: .\blaa will work
What is the results when you type

dir variable:erroractionpreference

Which version of PowerShell are you using?

I've just "upgraded" my home machine to CPT2 so I can't or am not willing
to go back to v1 yet.

However I'm seeing so oddities here

Can anyone who has CTPv2 answer the following question:

What do you get back when you type

dir c:\

what do you get back when you type

@'
dir c:\
'@

I'm not donig the happy dance. Howver I would have expected to see the
contents of my C:\ drive: When I get into work on Monday I can check whether
I'm doing something totally stupid or not.


I don't use here-string regularily with the one exception of using Brians
trick to commet out blocks of code so it may very will be I don't understand
what a here-string is as well as I thought.



"steve" wrote:
Quote:

>
> k guys , first let me thank you for the answers
> to start with Bob's answer, i tried your idea and it seems that power shell
> is just "swallowing" sqlplus coz i only get back the commands i typed between
> the @'.. '@.
> say
> @'
Quote:
Quote:

> >>sqlplus user/passwd
> >>drop table test;
> >> create table test(test varchar2(100);
> >>exit;
> >>'@
> >>
>
> sqlplus user/passwd
> drop table test;
> create table test(test varchar2(100);
> exit;
>
> i checked the database and nothing is executed !
> if your familiar with UNIX/Linux, you can have your program(not just
> sqlplus) grab the input ( the commands) from the shell using the syntax i
> showed you above - it's actually a kind of redirection '<<', your program
> will be reading those commands .thus when your shell script runs all that
> comes between @'..'@ is executed by the program not the shell. that's the
> behavior i'm seeking.
> and Shay, escaping the @ might clear things up for PS but not for sqlplus
> since @ has a special meaning for sqlplus, it instructs it that whatever
> follows '@' is an sql script relative-or-absolute path and it has to execute
> it so simply escaping '@' with something has no meaning for it.
>
> i assume this does not exist in windows just yet.
> "Shay Levi" wrote:
>
Quote:

> >
> > You can escape it with a backtick `@
> >
> > get more info:
> >
> > help about_Escape_character
> >
> > ---
> > Shay Levi
> > $cript Fanatic
> > http://scriptolog.blogspot.com
> >
Quote:

> > > i just downloaded powershell as i'm trying to migrate a bash script
> > > to a Windows compatible scripting language.my script used to connect
> > > to an oracle database and used heredocuments ( here strings) for this
> > > goal as follows
> > >
> > > sqlplus -L user/passwd << EOF
> > > oracle sqlplus commands go here
> > > EOF
> > > trying the same thing with power shell sqlplus -L user/passwd @'
> > >
> > >>> some commands
> > >>> '@
> > > would not work because the '@' symbol has another meaning for sqlplus.
> > > i'm wondering if there's analternative for '@' that would do the same
> > > job