pass exec function to string output

Make suggestions of things to add or change in Ubercode.

pass exec function to string output

Postby onykage on Wed Feb 18, 2009 5:35 pm

I think I mentioned this before. It would be really handy to have the ability to pass a string output from a command execution.

something like

string <- exec("cmd.exe", "cmd \c dir", exec_wait+sw_showminnoactive)
onykage
Admin
 
Posts: 221
Joined: Sat Jan 03, 2009 8:28 pm
Location: Armpit USA
Programming languages: php, java, python, ubercode, easyuo, peril, cobal, pascal, ruby

Re: pass exec function to string output

Postby ubercode on Wed Feb 18, 2009 6:17 pm

This would be possible. Exec would create a temporary file and would use the command processor to run the program and capture the output. Exec would have an extra inout parameter that would return the captured output. I prefer not to use the out parameter as most other languages use it to return the process's return code instead of a string, and this behaviour might also be added.

For:
  • Makes it easier to capture output and simplifies the command line

Against:
  • Hides the actual process that is going on (eg you don't know the temp file name etc).

Priority / Complexity:
  • Low or medium (one request only, not too difficuly to do)
ubercode
Site Owner
 
Posts: 274
Joined: Sun Jan 04, 2009 3:46 pm
Location: UK Channel Islands

Re: pass exec function to string output

Postby onykage on Wed Feb 18, 2009 7:59 pm

heh,

well my problem is there are several functions like this one, Ive been tempted to edit to allow for some custom stuff like this. I just dont want to break the environment or have to re-edit each class on an update.

Not so much of a problem and more of a strong desire tbh.
onykage
Admin
 
Posts: 221
Joined: Sat Jan 03, 2009 8:28 pm
Location: Armpit USA
Programming languages: php, java, python, ubercode, easyuo, peril, cobal, pascal, ruby

Re: pass exec function to string output

Postby ubercode on Fri Feb 20, 2009 8:02 pm

Actually you could create your own version of Exec with an extra string Inout parameter do do this. In pseudo code you want something like this:

Code: Select all
function Exec(in name:string[*] args:string[*] mode:integer inout captureText:string[*])
//
// Run a command line program and capture the output.
//
// name - Name of EXE file to run
// args - EXE file's arguments
// mode - must be EXEC_WAIT
// captureText - returns the output
//
  Get the folder containing [i]Name[/i] ...

  Create a temp file in this folder ...

  Change the logged folder to this folder ...

  newName <- "cmd.exe /c " + """" + ...the EXE file part of Name as a short name ...

  newArgs <- args (all filenames must be in short form) + " > " + tempfile + """"

  call Exec(newName, newArgs, EXEC_WAIT)

  at this point, tempfile exists and has the captured output ...

  call Loadfile(tempfile, FILE_TEXT, captureText)

  call Filedel(tempfile)

end function


The main complication is the filenames you pass to Exec must be in short form (like we talked about before). Either the caller has to use short form names, or the new version of Exec can find them automatically.
ubercode
Site Owner
 
Posts: 274
Joined: Sun Jan 04, 2009 3:46 pm
Location: UK Channel Islands


Return to Language Suggestions

Who is online

Users browsing this forum: No registered users and 1 guest

cron