![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
|
| | LinkBack | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | How to pass values from script to external batch files I've a batch file and a ps1 script Test1.bat powershell somescripts.ps1 robocopy c:\ d:\ <filename.txt> Somescripts.ps1 $filename = "abc.txt" After ps1 completes, i wish to pass the $filename abc.txt *outside* to robocopy command . Note that abc.txt was created in c:\ drive How do i do that ? Must i use process.start method in the script ? |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: How to pass values from script to external batch files On Nov 6, 2:53*am, "IT Staff" <jkk...@xxxxxx> wrote:
factor is Test1.bat. CMD doesn't have functionality that lets you do what you want directly. I can think of 4 answers. The simplest is to put 'robocopy c:\ d:\ <filename.txt>' in somescripts.ps1. The next simplest is to convert Test1.bat to PowerShell. You could also run SomeScripts.ps1 outside Test1.bat and have it call Test1.bat with your values as arguments. If you really MUST use CMD the way you've described I can only think of an ugly way. Have somescripts.ps1 write the value to a file then use FOR /F in your .bat to retrieve/use it. | ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) | ||||||||||||||||||||||||
| Guest | Re: How to pass values from script to external batch files Just a slightly more convenient procedure for the "ugly way": Write an external temp.bat from ps1 containing set filename=abc.txt and add the statement call temp.bat to your test1.bat. This makes %filename% directly available in your test1.bat environment But as Rick already recommends: Better migrate the whole job to somescripts.ps1 and do not mix ps1 and bat if they need to interact. -- Gerd "RickB" wrote:
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #4 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: How to pass values from script to external batch files I see, so it is better to put all batch statements into ps1 and have only one script running ... "Gerd Schneider" <GerdSchneider@xxxxxx> wrote in message news:0DB8E844-7DD2-42A0-AB3C-05997D31DC66@xxxxxx
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #5 (permalink) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Guest | Re: How to pass values from script to external batch files If you find some reason to break up a script into pieces there is nothing intrinsically wrong with that. Just be sure the top most one is PowerShell. IOW call a .bat from .ps1, not the other way around. On Nov 6, 7:03*pm, "IT Staff" <jkk...@xxxxxx> wrote:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | #6 (permalink) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Guest | Re: How to pass values from script to external batch files Good advice, but, imho, the limitation still exists that the called script cannot easily pass information back to the calling script, regardless of which is batch and which is powershell. Given that powershell encapsulates just about every feature of batch (and then some) the best approach would be to convert everything to powershell. It's a bit different with a combination, for example, of batch and vbscript. Although vbscript is much better than batch at some things (complex logic, object programming, text parsing, etc.), it is often easier to code some things in batch (or just leave existing code in batch), especially in the area of file processing. /Al "RickB" <rbielaws@xxxxxx> wrote in message news:77080eae-62d5-42d4-8aef-05c1dffe149e@xxxxxx If you find some reason to break up a script into pieces there is nothing intrinsically wrong with that. Just be sure the top most one is PowerShell. IOW call a .bat from .ps1, not the other way around. On Nov 6, 7:03 pm, "IT Staff" <jkk...@xxxxxx> wrote:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | #7 (permalink) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Guest | Re: How to pass values from script to external batch files Good advice, but, imho, the limitation still exists that the called script cannot easily pass information back to the calling script, regardless of which is batch and which is powershell. Given that powershell encapsulates just about every feature of batch (and then some) the best approach would be to convert everything to powershell. It's a bit different with a combination, for example, of batch and vbscript. Although vbscript is much better than batch at some things (complex logic, object programming, text parsing, etc.), it is often easier to code some things in batch (or just leave existing code in batch), especially in the area of file processing. /Al "RickB" <rbielaws@xxxxxx> wrote in message news:77080eae-62d5-42d4-8aef-05c1dffe149e@xxxxxx If you find some reason to break up a script into pieces there is nothing intrinsically wrong with that. Just be sure the top most one is PowerShell. IOW call a .bat from .ps1, not the other way around. On Nov 6, 7:03 pm, "IT Staff" <jkk...@xxxxxx> wrote:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How can i pass values from external files | IT Staff | PowerShell | 0 | 10-29-2008 10:42 PM |
| Pop-up to enter variables to pass to script | Anatoli | PowerShell | 2 | 11-17-2007 01:38 AM |
| returning values to original script | Frank | PowerShell | 1 | 05-25-2007 04:53 PM |
| Batch Script | jon | PowerShell | 1 | 12-01-2006 07:30 PM |
| Run tasks asynchronously: external files vs. script blocks | OK | PowerShell | 7 | 11-05-2006 01:38 PM |