1. Subin Subash
  2. PowerBuilder
  3. Monday, 13 January 2020 10:59 AM UTC

Hi,

 

  I have configured AWS CLI for copying files from AWS to Local System and It is working from command Prompt (cmd.exe).

 

I can run cmd.exe from PowerBuilder using Run() function . But how I will run cmd and run the below command in cmd from PowerBuilder.

 

aws s3 cp  s3://source_path/ d:\destination_path\ --recursive

 

Kevin Ridley Accepted Answer Pending Moderation
  1. Tuesday, 14 January 2020 18:25 PM UTC
  2. PowerBuilder
  3. # 1

You should also be able to use the AWS REST API to do this instead.

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Monday, 13 January 2020 13:50 PM UTC
  2. PowerBuilder
  3. # 2
Comment
  1. Chris Pollach @Appeon
  2. Monday, 13 January 2020 17:46 PM UTC
Hi Subin;

Have you tried ...

cmd.exe aws s3 cp s3:/source_path/ D:\destination_path\ --recursive

Regards ... Chris

  1. Helpful
  1. Roland Smith
  2. Monday, 13 January 2020 17:52 PM UTC
The bat file is only an example, you can execute any program using my code.
  1. Helpful
  1. Subin Subash
  2. Tuesday, 14 January 2020 04:52 AM UTC
Hi Chris,

I have tried Run('cmd.exe aws s3 cp s3:/source_path/ D:\destination_path\ --recursive')



But it will pop-up the command prompt window and it is not working
  1. Helpful
There are no comments made yet.
John Raghanti Accepted Answer Pending Moderation
  1. Monday, 13 January 2020 13:04 PM UTC
  2. PowerBuilder
  3. # 3

Function Long GetEnvironmentStringsA() Library "kernel32"

Function Long CreateProcessA (String app_name, String CommandLine, Long ProcAttributes, Long ThreadAttributes, Boolean InheritHandles, Long CreationFlags, Long EnvBlock, String CurrentDirectory, StartUpInfo start, ref ProcessInfo proc) library "kernel32" alias for "CreateProcessA;Ansi"

Function Long FreeEnvironmentStringsA(Long lpEnv) Library "kernel32"

Function Long GetExitCodeProcess(long hproc, ref long ExitCode) Library "kernel32"

 

global type processinfo from structure
long hProcess
long hThread
long dwProcessId
long dwThreadId
end type

global type startupinfo from structure
long cb
long lpReserved
long lpDesktop
long lpTitle
long dwX
long dwY
long dwXSize
long dwYSize
long dwXCountChars
long dwYCountChars
long dwFillAttribute
long dwFlags
long wShowWindow
long cbReserved2
long lpReserved2
long hStdInput
long hStdOutput
long hStdError
end type

 


public function boolean run (string as_commandstring, string as_workingdirectory, ref long al_returncode, boolean ab_waitforprocess);Long ll_rtn, ll_envBlock, ll_ExitCode, ll_okay
StartUpInfo lst_inf
ProcessInfo lpi_inf
String ls_null
Boolean lb_rtn

// Setup StartUp Info
lst_inf.cb = 68
lst_inf.lpReserved = 0
lst_inf.lpDesktop = 0
lst_inf.lpTitle = 0
lst_inf.dwX = 0
lst_inf.dwY = 0
lst_inf.dwXSize = 0
lst_inf.dwYSize = 0
lst_inf.dwXCountChars = 0
lst_inf.dwYCountChars = 0
lst_inf.dwFillAttribute = 0
lst_inf.dwFlags = 0
lst_inf.wShowWindow = 0
lst_inf.cbReserved2 = 0
lst_inf.lpReserved2 = 0
lst_inf.hStdInput = 0
lst_inf.hStdOutput = 0
lst_inf.hStdError = 0

lpi_inf.hProcess = 0
lpi_inf.hThread = 0

SetNull(ls_null)
// Start The Process

If Not ab_waitforprocess Then
ll_envBlock = GetEnvironmentStringsA()
FreeEnvironmentStringsA(ll_envBlock)
ll_rtn = CreateProcessA(ls_null, as_commandstring, 0, 0, False, 32 /* NORMAL_PRIORITY */, ll_envBlock, as_workingdirectory, lst_inf, lpi_inf)
Else
ll_rtn = CreateProcessA(ls_null, as_commandstring, 0, 0, False, 32 /* NORMAL_PRIORITY */, 0, as_workingdirectory, lst_inf, lpi_inf)
End If

If ll_rtn = 0 Then
// CreateProcess Failed...
FreeEnvironmentStringsA(ll_envBlock)
Return False
End If

// don't need thread handle
If CloseHandle(lpi_inf.hThread) = 0 Then
MessageBox("Run", "CloseHandle() for ThreadHandle failed!")
MessageBox("GetLastError", GetLastError())
End If

If Not ab_waitforprocess Then
// don't need the process handle if we are not waiting for it
CloseHandle(lpi_inf.hProcess)
Else
ll_okay = GetExitCodeProcess(lpi_inf.hProcess, ll_ExitCode)
Do while ll_okay <> 0
If ll_ExitCode <> 259 /* STILL_ACTIVE */ Then
al_returncode = ll_ExitCode /* Save the programs return code */
Exit /* get out of the loop */
End If
Yield()
ll_okay = GetExitCodeProcess(lpi_inf.hProcess, ll_ExitCode)
Loop

If CloseHandle(lpi_inf.hProcess) = 0 Then
MessageBox("Run", "CloseHandle() for ProcHandle failed!")
MessageBox("GetLastError", GetLastError())
End If
FreeEnvironmentStringsA(ll_envBlock)
End If

Return True
end function

 

 

Usage:

string ls_command

Long ll_rtn

ls_command = is_somePath + "fileprt.exe " + as_filename + " " + String(ai_fontsize) // You won't have this exe

Run(ls_command, is_haPath, ll_rtn, True)

 

Comment
  1. Michael Kramer
  2. Monday, 13 January 2020 13:16 PM UTC
Hey John, great extension to system function = Run !
  1. Helpful
There are no comments made yet.
David Peace (Powersoft) Accepted Answer Pending Moderation
  1. Monday, 13 January 2020 12:36 PM UTC
  2. PowerBuilder
  3. # 4

Hi

The simple solution is to write your command to a batch file say runit.cmd and then run that from PB. OR you cn run the command "aws s3 cp  s3://source_path/ d:\destination_path\ --recursive" from PB.

Hope that helps

David

Comment
  1. Subin Subash
  2. Monday, 13 January 2020 13:04 PM UTC
Hi David,



I have given the below command from PB



Environment env

String ls_command

long li_cmd



GetEnvironment(env)



ls_command = 'aws s3 cp s3:/source_path/ D:\destination_path\ --recursive'



Choose Case env.OSType

Case windows!

ls_command = 'command.com /c ' + ls_command

Case windowsnt!

ls_command = 'cmd.exe /c "' + ls_command + '"'

Case else

ls_command = 'cmd.exe /c "' + ls_command + '"'

End Choose



li_cmd = Run(ls_command,Maximized!)



But it's not working
  1. Helpful
  1. David Peace (Powersoft)
  2. Monday, 13 January 2020 13:11 PM UTC
why not try run("mycmd.cmd")
  1. Helpful
  1. Michael Kramer
  2. Monday, 13 January 2020 13:23 PM UTC
I would encapsulate AWS commands into a .CMD or .PS1 file. Then call that from PB app.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.