Re: Passing back results to calling command or CD

2005-04-19 Thread $Bill Luebkert
Glenn Linderman wrote:

> On approximately 4/19/2005 8:57 AM, came the following characters from 
> the keyboard of $Bill Luebkert:
...
> cd /?
> 
> tells about the  cd /d  option... which changes drives as well as paths...
> 
> And yes, that doesn't work on all versions of windows, but neither does 
> "for /F"...

Good catch - I don't play with batch files or cmd much, but that works:

@echo off
for /F "usebackq delims=?" %%I in (`perl E:\home\dbe\foo\fo.pl %1`) do cd /d %%I

-- 
  ,-/-  __  _  _ $Bill LuebkertMailto:[EMAIL PROTECTED]
 (_/   /  )// //   DBE CollectiblesMailto:[EMAIL PROTECTED]
  / ) /--<  o // //  Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Passing back results to calling command or CD

2005-04-19 Thread $Bill Luebkert
andrew Black wrote:

> $Bill Luebkert wrote:
> 
> 
>>Did a little searching and came up with this to replace the above 2 lines :
>>
>>   for /F "usebackq" %%i in (`perl find_dir.pl %1`) do cd %%i
>>
> 
> Cheers - that does the trick.   I was trying to look for a way of 
> putting the result of a command into a variable.
> 
> A slight refinement I found I needed - the above version stumbled on
> files involving spaces ...
> for /F "usebackq delims=,"   ... as before
> I am assuming the "," is not a valid character in a filename.

You could use '?' (wildcard char - can't be in a filename).
Note that cd on Windoze won't cross disk boundaries, so to be really
useful, you should have a way to change drives if necessary.

This seems to handle it but there ought to be a way to do it with
one line instead of 2 :

@echo off
for /F "usebackq" %%I in (`perl E:\home\dbe\test.pl %1`) do %%~dI
for /F "usebackq delims=?" %%J in (`perl E:\home\dbe\test.pl %1`) do cd %%J

-- 
  ,-/-  __  _  _ $Bill LuebkertMailto:[EMAIL PROTECTED]
 (_/   /  )// //   DBE CollectiblesMailto:[EMAIL PROTECTED]
  / ) /--<  o // //  Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Passing back results to calling command or CD

2005-04-19 Thread andrew Black
$Bill Luebkert wrote:
Did a little searching and came up with this to replace the above 2 lines :
   for /F "usebackq" %%i in (`perl find_dir.pl %1`) do cd %%i
Cheers - that does the trick.   I was trying to look for a way of 
putting the result of a command into a variable.

A slight refinement I found I needed - the above version stumbled on
files involving spaces ...
   for /F "usebackq delims=,"   ... as before
I am assuming the "," is not a valid character in a filename.
Thanks again for the very useful hint.
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Passing back results to calling command or CD

2005-04-19 Thread Chris Wagner


Quoting O'Reilly book:
Every process[2] has its own current directory. When a new process is
launched, it inherits its parent's current directory, but that's the end of
the connection. If your Perl program changes its directory, it won't affect
the parent shell (or whatever) that launched the Perl process. Likewise, the
processes that the Perl program creates cannot affect that Perl program's
current directory. The current directories for these new processes are
inherited from the Perl program's current directory.


At 09:37 AM 4/19/05 +0100, andrew Black wrote:
>In a bit more detail as to what I am trying to do at application level.
>I want to be able to type "mycd test" and this looks up test in a flat 
>file and finds
>test  :  c:\blah\blah\moreblah\test


However, if ur running the Bash shell u can do this.  Then ur mycd command
is a bash script that can optionally have a perl component.

#!/bin/bash
$destdir=`perlscript.pl $1`
cd $destdir
exit

Your bash shell will now be in that directory.








--
REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=--
"...ne cede males"

0100

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Passing back results to calling command or CD

2005-04-19 Thread $Bill Luebkert
andrew Black wrote:

> Hi
> I am trying to write a program that will allow me to CD to various 
> places (more details later). I want to call this from the windows 
> command line (cmd).
> 
> Ways I have tried are
>   - use Perl "chdir" - but this only affects the perl process. The 
> caller  doesn't see that change.
>   - write a bat file that calls the Perl which somehow returns the 
> result back to the bat file that can then CD for you.  How can you 
> return this
>  REM  mycd.bat
>  perl find_dir.pl   %1
>  cd  %directory_returned_by_find_dir%

Did a little searching and came up with this to replace the above 2 lines :

   for /F "usebackq" %%i in (`perl find_dir.pl %1`) do cd %%i


> 
> In a bit more detail as to what I am trying to do at application level.
> I want to be able to type "mycd test" and this looks up test in a flat 
> file and finds
> test  :  c:\blah\blah\moreblah\test
> and cds you to the correct directory
> 
> Any thoughts as to how to do this



-- 
  ,-/-  __  _  _ $Bill LuebkertMailto:[EMAIL PROTECTED]
 (_/   /  )// //   DBE CollectiblesMailto:[EMAIL PROTECTED]
  / ) /--<  o // //  Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Passing back results to calling command or CD

2005-04-19 Thread Chris Wagner
One MORE thing.  If u set an alias u can dispense with the . on the command
line.  Set an alias like "alias mycd='. mycd.sh'.  That way the . is taken
care of within the alias and u don't have to type it.  The mycd.sh script
can do anything u want to come up with a dir name to cd to.






--
REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=--
"...ne cede males"

0100

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Passing back results to calling command or CD

2005-04-19 Thread Chris Wagner
#!/bin/bash
$destdir=`perlscript.pl $1`
cd $destdir
exit

I need to clarify one thing.  You have to invoke the script with a . infront
of it so that bash will *not* spawn a subshell.
[host:/c]$ . mycd blah
[host:/blah]$







--
REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=--
"...ne cede males"

0100

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Passing back results to calling command or CD

2005-04-19 Thread Chris Wagner
Quoting O'Reilly book:
Every process[2] has its own current directory. When a new process is
launched, it inherits its parent's current directory, but that's the end of
the connection. If your Perl program changes its directory, it won't affect
the parent shell (or whatever) that launched the Perl process. Likewise, the
processes that the Perl program creates cannot affect that Perl program's
current directory. The current directories for these new processes are
inherited from the Perl program's current directory.


At 09:37 AM 4/19/05 +0100, andrew Black wrote:
>In a bit more detail as to what I am trying to do at application level.
>I want to be able to type "mycd test" and this looks up test in a flat 
>file and finds
>test  :  c:\blah\blah\moreblah\test


However, if ur running the Bash shell u can do this.  Then ur mycd command
is a bash script that can optionally have a perl component.

#!/bin/bash
$destdir=`perlscript.pl $1`
cd $destdir
exit

Your bash shell will now be in that directory.








--
REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=--
"...ne cede males"

0100

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: Passing back results to calling command or CD

2005-04-19 Thread Anderson, Mark (Service Delivery)
this is one of the standard annoyances... the concept of a CDW, PWD, OLDPWD
or whatever is a shell environment variable... 

1) so you create a new shell (perl.exe) and cs somewhere and store the
directory in a file... (or whatever)
2) your batch file (running in a cmd.exe of its own) then does a cd to this
same directory
3) then cmd.exe exits and drops you back out in the original CMD.exe in its
original working directory because each shell has its own copy which is
propagated to its kids...

on a unix box you'd be tempted just to do: 
#!/bin/sh
#mycd.bat
perl find_dir.pl   %1
  cd  %directory_returned_by_find_dir%
  export $NEWDIR=$PWD   
  exec $SHELL

which probably looks like it works on the surface, but probably doesn't if
you look hard enough (because it starts a new shell) 
You'd achieve this on unix by updating the .bashrc or whatever with a cd
$NEWDIR command however you still get a brand new shell which might not be
any use to you. 

Kind regards,

Mark Anderson
Service Improvement Programme
Level 2, 113 Dundas Street
Edinburgh, EH3 5DE
Tel: 0131 523 8786
Mob: 07808 826 063


> -Original Message-
> From: [EMAIL PROTECTED]
> [SMTP:[EMAIL PROTECTED] On Behalf Of
> andrew Black
> Sent: Tuesday, April 19, 2005 9:38 AM
> To:   perl-win32-users
> Subject:  Passing back results to calling command or CD
> 
> *** WARNING : This message originates from the Internet ***
> 
> Hi
> I am trying to write a program that will allow me to CD to various 
> places (more details later). I want to call this from the windows 
> command line (cmd).
> 
> Ways I have tried are
>   - use Perl "chdir" - but this only affects the perl process. The 
> caller  doesn't see that change.
>   - write a bat file that calls the Perl which somehow returns the 
> result back to the bat file that can then CD for you.  How can you 
> return this
>  REM  mycd.bat
>  perl find_dir.pl   %1
>  cd  %directory_returned_by_find_dir%
> 
> In a bit more detail as to what I am trying to do at application level.
> I want to be able to type "mycd test" and this looks up test in a flat 
> file and finds
> test  :  c:\blah\blah\moreblah\test
> and cds you to the correct directory
> 
> Any thoughts as to how to do this
> ___
> Perl-Win32-Users mailing list
> Perl-Win32-Users@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


The Royal Bank of Scotland plc, Registered in Scotland No. 90312. Registered 
Office: 36 St Andrew Square, Edinburgh EH2 2YB

The Royal Bank of Scotland plc is authorised and regulated by the Financial 
Services Authority and represents The Royal Bank of Scotland Marketing Group. 
The Bank sells life policies, collective investment schemes and pension 
products and advises only on the Marketing Group's range of these products and 
on a With-Profit Bond produced by Norwich Union Life (RBS) Limited.

This e-mail message is confidential and for use by the addressee only. If the 
message is received by anyone other than the addressee, please return the 
message to the sender by replying to it and then delete the message from your 
computer. Internet e-mails are not necessarily secure. The Royal Bank of 
Scotland plc does not accept responsibility for changes made to this message 
after it was sent.

Whilst all reasonable care has been taken to avoid the transmission of viruses, 
it is the responsibility of the recipient to ensure that the onward 
transmission, opening or use of this message and any attachments will not 
adversely affect its systems or data. No responsibility is accepted by The 
Royal Bank of Scotland plc in this regard and the recipient should carry out 
such virus and other checks as it considers appropriate.

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs