Ivanus
25th September 2014, 15:28
We are about to migrate BaanERP 5.0c from UNIX/Oracle to Windows/MS-SQL. We are having a lot of scripts and so we rebuild all the scripts with Powershell.
From the PowerShell Console everything is working fine but now we are having problems to run the script with using run.prog().
If I use a Batch-File which runs the .PS1 it's working.
Is there a way to start the Powershell-Script directly with run.prog() ?

Thanks

mark_h
25th September 2014, 15:54
Maybe if you post the snippet of code with what the run.prog looks like maybe someone will see the issue.

vamsi_gujjula
25th September 2014, 17:54
Here is a code snippet from ERPLN

| cmd = "PowerShell -ExecutionPolicy Bypass ; " & local.script.file
| rc = start.application.local(cmd, true, exit.code,"")

this is running prowershell script from client's command prompt

Ivanus
25th September 2014, 18:47
This is what I was trying (not working):

command.line = "powershell -executionPolicy bypass -file d:\script\vk.auftragskorrektur.mail.ps1 " & mail.subject & " " & mail.recipients

err = run.prog(command.line,"",RP_NOWAIT)

vinceco252
25th September 2014, 19:06
What kind or errors/logging are you getting?

Vince

Ivanus
25th September 2014, 19:27
This is what I can see in the Application log:

Env : erp61 (D:\Infor\bse)
Program : bshell file \logic\mir\mir\sh_fun.c # 630
Keyword : sh_server
User : sv8 type:S language:3 locale:ISO88591/NULL
Process : 5876
Proc.Set : sv8adm@abcd.com:9996
Lasterror : 0
Errno : 0
Bdberrno : 0
ExtraInfo : session: "awitm4200m000";object: "awitm4200m000"; function: "<28>" run.prog; company number: 2
Message : Shell server replied with error: CreateProcess of '"PowerShell -executionPolicy bypass;d:\script\bfwall.logging.ps1" ' failed. Error The system cannot find the file specified. (error value: 2)

benito
25th September 2014, 21:01
can you add the switch -Noprofile? also can you put "vk.auftragskorrektur.mail.ps1" in the same directory and get rid of the path? another thing you can try instead of -file put -Command

vamsi_gujjula
26th September 2014, 07:53
The Error say it cannot find the File for some reason .. let me try with run.prog()

Ivanus
26th September 2014, 08:46
Good morning. In the meantime I tried the switch -noprofile, I tried -command instead of -file and I copied the script in the same folder of the powershell.exe - unfortunately the same result
Message : Shell server replied with error: CreateProcess of '"PowerShell -noprofile -executionPolicy bypass -file bfwall.logging.ps1" ' failed. Error The system cannot find the file specified. (error value: 2)
When I do a run on the server with exactly this command it's working :( - I really have no more ideas

bhushanchanda
26th September 2014, 10:34
Message : Shell server replied with error: CreateProcess of '"PowerShell -noprofile -executionPolicy bypass -file bfwall.logging.ps1" '

Are you sure this is the right path? In the previous post you mention the path with D:\... Now, you are using file name directly.

Ivanus
26th September 2014, 10:42
I tried it with several variants, directly with D:\..., via UNC path \\Server\d$\FileName,
I put the file directly on C:\ and always the same result
I'm not having issues when I'm starting Batchfiles via run.prog() - this is always working - the issue only exists when I try to start a PowerShell script

bhushanchanda
26th September 2014, 10:45
What you can try is, add the powershell script to a bat file and then run it using run.prog(). I hope it won't require Admin Privileges.

bhushanchanda
26th September 2014, 10:48
And, you can also try setting path before executing your command.

set PATH=%PATH%;"D:\path_where_file_is_kept"

Also, try specifying Powershell path as well

e.g.

C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -File "D:\TFS_WDIR\Test Project\abc.ps1"

May be its not able to find Powershell itself.

Ivanus
26th September 2014, 11:11
Thanks for the good tips but already tried with the whole path to powershell.exe - tried with the set PATH right now but unfortunately still not working.
When I but the script in a bat file with run.prog() it's working fine but I was hoping that there is another way because we are having more the 100 scripts and I want to avoid to create a bat file for each script.
I have to correct about 200 Programscripts so my wish was to find the fastest and easiest way ;)

bhushanchanda
26th September 2014, 11:20
One more thing you can try is:-

command.line = "powershell -executionPolicy bypass -file d:\script\vk.auftragskorrektur.mail.ps1 " & mail.subject & " " & mail.recipients


Spilt the above command into 2 parts. First part powershell.exe/powershell/full_path_of_powershell and second part as the arguments.

err = run.prog(first_part,second_part,RP_NOWAIT,"","C:\temp\err.txt")

Now, you can check what errors are you getting in the text file.

Ivanus
26th September 2014, 12:32
GREAT !! That's working now

bhushanchanda
26th September 2014, 12:36
Glad that worked. Please post your running code. Will help others.

Ivanus
23rd October 2014, 16:02
result is to sent a mail with 2 Parameters (subject and recipients) and a text created in "abc.txt"

long err

string mail.subject(27),
mail.recipients(255)

string part1(255),
part2(255)

seq.open("D:\Mail.Notifications\abc.txt","wt+")

part1 = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
part2 = "D:\SCRIPT\vk.auftragskorrektur.mail.ps1 " & mail.subject &" "& mail.recipients

err = run.prog(part1,part2,RP_NOWAIT)