1. ahmed tawfik
  2. PowerBuilder
  3. Monday, 26 July 2021 12:24 PM UTC

Hi all

in CMD  env.

when i wrote       ping 8.8.8.8  > E:\out.txt

the output of this command is written to e:\out.txt

 

but in PB env

when i wrote

Run(" ping 8.8.8.8  > E:\out.txt")

or even  

Run(" ping 8.8.8.8  > E:\out.txt", Maximized!)

 

there was no output file?

what is error?

Thanks

Ahmed

 

René Ullrich Accepted Answer Pending Moderation
  1. Monday, 26 July 2021 13:04 PM UTC
  2. PowerBuilder
  3. # 1

Run command simply starts a command. But you can't redirexct input or output directly.

This should work:

Run('cmd /c "ping 8.8.8.8  > E:\out.txt"') 

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Monday, 26 July 2021 13:39 PM UTC
  2. PowerBuilder
  3. # 2

The Run function does not wait for the external command/program to finish. Your code was looking for the file before it was created.

This code example has a run and wait function:

https://www.topwizprogramming.com/freecode_runandwait.html

This code example does Ping using Windows API functions:

https://www.topwizprogramming.com/freecode_ping.html

 

Comment
There are no comments made yet.
ahmed tawfik Accepted Answer Pending Moderation
  1. Monday, 26 July 2021 17:57 PM UTC
  2. PowerBuilder
  3. # 3

Hi René Ullric

cmd /c "ping ..........

what /c refer to

and how to ensure that cmd will be open in a specific dir

for example when i type  cmd  i want to open at e:\dir1 (file folder) in which I  want to run specific command

Regards

Ahmed

 

Comment
  1. ahmed tawfik
  2. Monday, 26 July 2021 18:05 PM UTC
also i want the cmd screen not to be closed immediately after run command but wait for 5 seconds for example
  1. Helpful
  1. ahmed tawfik
  2. Monday, 26 July 2021 19:12 PM UTC
what if i want to put variable instead of fixed file name



as

Run('cmd /c "ping 8.8.8.8 > " + ls_var + ')



  1. Helpful
  1. René Ullrich
  2. Tuesday, 27 July 2021 05:25 AM UTC
To find more info about CMD command line parameters run "help cmd" in a command prompt or google for it..

/C runs a command and exits. If you use /K instead the prompt will remain open.



It is also possible to specify more then one command to run. Read the help for CMD. So you have a chance to do what you want - change directory (cd /d ...) or wait some seconds (timeout ...).



Because it is a simple string that you specify for the Run function you can use powerbuilder variables to create the string as in your example.

  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.