?
Solved

Running a network located exe using powershell from a batch file

Posted on 2012-08-17
8
Medium Priority
?
2,496 Views
Last Modified: 2012-08-21
Right, what I need doing is to run this command exactly...

\\PUMA\RMCOBOLV12\RUNCOBOL.EXE CAR001 K L=\\PUMA\RMCOBOLV12\WOWRT.DLL C=PRT.CFG

but with the working directory being

\\PUMA\CARPLAN\CARPLANLIVE


I need to write this command and its working directory into a .ps1 file, which will be called up by a batch file (the reason why is a long story!).  I've placed the .ps1 file into C:\Program Files (x86)\CarPlan

My .ps1 file at the minute is...

start-process -filepath "\\PUMA\RMCOBOLV12\RUNCOBOL.EXE CAR001 K L=\\PUMA\RMCOBOLV12\WOWRT.DLL C=PRT.CFG" -workingdirectory "\\PUMA\CARPLAN\CARPLANLIVE"

and my batch file at the minute is...

powershell.exe -File "C:\Program Files (x86)\Puma CarPlan\Puma CarPlan.ps1"


I'm a complete beginner to powershell.  I figure it's something to do with the "-filepath" switch because what it isn't just a file path is it, it a whole command, with switches and the like.  This is what I get...


Start-Process : This command cannot be executed due to the error: The system ca
nnot find the file specified.
At C:\Program Files (x86)\Puma CarPlan\Puma CarPlan.ps1:1 char:14
+ start-process <<<<  -filepath "\\PUMA\RMCOBOLV12\RUNCOBOL.EXE CAR001 K L=\\PU
MA\RMCOBOLV12\WOWRT.DLL C=PRT.CFG" -workingdirectory "\\PUMA\CARPLAN\CARPLANLIV
E"
    + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOp
   erationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.C
   ommands.StartProcessCommand



but if I change the "-filepath" to "-command" I get...



Start-Process : A parameter cannot be found that matches parameter name 'comman
d'.
At C:\Program Files (x86)\Puma CarPlan\Puma CarPlan.ps1:1 char:23
+ start-process -command <<<<  "\\PUMA\RMCOBOLV12\RUNCOBOL.EXE CAR001 K L=\\PUM
A\RMCOBOLV12\WOWRT.DLL C=PRT.CFG" -workingdirectory "\\PUMA\CARPLAN\CARPLANLIVE
"
    + CategoryInfo          : InvalidArgument: (:) [Start-Process], ParameterB
   indingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Comm
   ands.StartProcessCommand
0
Comment
Question by:meirionwyllt
  • 3
  • 3
7 Comments
 
LVL 3

Expert Comment

by:Akulsh
ID: 38306652
If I understand your situation correctly, there may be no need to bother with Powershell. Just create a batch file (*.bat), containing the following:

net use X: \\PUMA\CARPLAN\CARPLANLIVE

X:

\\PUMA\RMCOBOLV12\RUNCOBOL.EXE CAR001 K L=\\PUMA\RMCOBOLV12\WOWRT.DLL C=PRT.CFG


Here, X: is the name of mapped drive. You can use any other available letter.

If the last line -- whose syntax, I presume, is correct -- does not run from X: drive, you may want to map \\PUMA\RMCOBOLV12 to another drive, say Y:, and then run (from X drive)

Y:\RUNCOBOL.EXE CAR001 K L=\\PUMA\RMCOBOLV12\WOWRT.DLL C=PRT.CFG
0
 
LVL 71

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 38307862
You are correct in suspecting the filepath string is incorrect. You need to split command and arguments into two strings:
start-process `
   -FilePath "\\PUMA\RMCOBOLV12\RUNCOBOL.EXE" `
   -ArgumentList "CAR001 K L=\\PUMA\RMCOBOLV12\WOWRT.DLL C=PRT.CFG" `
   -workingdirectory "\\PUMA\CARPLAN\CARPLANLIVE"

Open in new window

You can omit both the "-FilePath" and "-ArgumentList" parametername to make the command shorter. You can also remove the backticks and write all in one line.
0
 

Author Comment

by:meirionwyllt
ID: 38310823
Qlemo, I tried all in one line like you suggested at the end of your post (simply because I don't understand the backticks or how to use them :), i.e.

start-process -FilePath "\\PUMA\RMCOBOLV12\RUNCOBOL.EXE" -ArgumentList "CAR001 K L=\\PUMA\RMCOBOLV12\WOWRT.DLL C=PRT.CFG" -workingdirectory "\\PUMA\CARPLAN\CARPLANLIVE"

but what I got back was...

Start-Process : This command cannot be executed due to the error: The applicati
on has failed to start because its side-by-side configuration is incorrect. Ple
ase see the application event log or use the command-line sxstrace.exe tool for
 more detail.
At C:\Program Files (x86)\Puma CarPlan\Puma CarPlan.ps1:1 char:14
+ start-process <<<<  -FilePath "\\PUMA\RMCOBOLV12\RUNCOBOL.EXE" -ArgumentList
"CAR001 K L=\\PUMA\RMCOBOLV12\WOWRT.DLL C=PRT.CFG" -workingdirectory "\\PUMA\CARPLAN\CARPLANLIVE"
    + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOp
   erationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.C
   ommands.StartProcessCommand


Any idea what might be wrong?


[Just to check - the batch command that I'm unning is...

powershell.exe -File "C:\Program Files (x86)\Puma CarPlan\Puma CarPlan.ps1"

is this OK?]


Thanks
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 71

Expert Comment

by:Qlemo
ID: 38310924
The backtick is the PS escape character. Put as last on a command line, it says the line continues in the next one. If you copy and paste my code, it should work the same as your all-in-a-single-line command.

The Side-by-Side config issue however is something completely different. As your first tries with start-process "worked", we can exclude start-process as throwing that exception for itself. Conclusion: The application you want to call needs some (.Net) assemblies to run, which are not present.
A "Side-by-Side config" consists of
a manifest (telling the system which .Net assemblies are needed, and their required release), which can be stored in the application itself or distributed as additional file  «appname».manifest
the assemblies stored in the WinSxS folder of your system, as requested in the manifest.
As I guess there is an installation/configuration issue, could you start cmd.exe and issue
start "Test" /D \\PUMA\CARPLAN\CARPLANLIVE \\PUMA\RMCOBOLV12\RUNCOBOL.EXE CAR001 K L=\\PUMA\RMCOBOLV12\WOWRT.DLL C=PRT.CFG

Open in new window

and see if you get the same error?
0
 

Author Comment

by:meirionwyllt
ID: 38311148
Ah.  Yeah, I didn't want this to happen - I was hoping that my problem was just a powershell syntax error, but I'm now certain that the help you've given me has sorted the powershell side of the problem.

The command in cmd.exe worked fine.

One thing I didn't explain earlier is the fact that it's not a local install that I'm doing - it's a Citrix Stream, so the error I'm getting is due to something not streaming properly.

Both the profiler and target have both Visual C++ 2005 SP1 and .NET Framework 4 Full installed.

I don't suppose you have expertise in Citrix Streaming do you?

I'm gonna give you the points for this anyway, because the powershell side is now fine.

Thanks
0
 

Author Comment

by:meirionwyllt
ID: 38311163
For what it's worth, how do I use the sxstrace.exe tool ?  I might as well add it to the batch file that is launched.

Is it a matter of...?

1.  Running sxstrace.exe with switch to turn tracing on
2.  Running the troublesome command
3.  Running sxstrace.exe with switch to turn tracing off

thanks.
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 38311236
Yes, that is the way I read sxstrace to be used. But never did that myself up to now.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For anyone that has accidentally used newSID with Server 2008 R2 (like I did) and hasn't been able to get the server running again because you were unlucky (as I was) and had no backups - I was able to get things working by doing a Registry Hive rec…
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question