Page 1 of 1

need help about command line passing and more T_T

Posted: Tue Feb 24, 2009 7:03 pm
by shadowslash
i'm quite new to runtime revolution and i'd want to know how to retrieve a command line that's going to be passed to my program..., i'd also want to know how to get the selected file's file name and extension only (through answer file command) not the whole path... i think the possibilities are endless with runtime revolution but i would need some help in achieving stuff that i'm not familiar with T_T anybody please help me out... thanks in advance.. (SCRIPTS PLEASE) :(

Posted: Tue Feb 24, 2009 8:14 pm
by Mark
Dear shadowslash,

First of all, I must recommend that you try things first, before asking questions. People here don't mind posting scripts, if you first post your own script to show what exactly you are trying to achieve. Writing a script for someone without knowing exactly what this person wants is very time consuming, but correcting someone else's script is very easy and usually takes no longer than a minute.

I'll try to give you a few hints. To get the result from command line syntax, you use the shell command:

Code: Select all

put shell("dir") into myVar
put shell("ipconfig /all") into myNetworkInfo
I'm not sure what you mean with selected file's file name, but to get the extension of a file, you can try this:

Code: Select all

constant dot = "."
function fileExtension theFilePath
  set the itemdel to slash
  if last item of theFilePath contains dot then
    set the itemDel to dot
    return last item of theFilePath
  else
    return empty
  end if
end fileExtension
I hope this helps.

Best,

Mark

Posted: Tue Feb 24, 2009 8:48 pm
by shadowslash
i'm sorry coz the internet connection at our house got crappy and stuff so i'm here at my pal's place instead.. he doesn't have Runtime Revolution and i forgot to bring with me my sample script, i'll try to define what i need in as much understandable manner as i can T_T

1. i just want to know how to get the command line that will be passed to my program just in case somebody uses it.

example:
i made a text viewer / editor, if ever i'm going to associate my program to a certain file extension like *.ext, how do i get the command line that will be passed to it whenever a *.ext file will be opened with it.. in notepad, when you open a *.txt file with notepad, it loads the contents of the *.txt file right? that's what i wanna do with my program too, to be able to make my program detect which file was opened with it and then load the contents of that file into my program.. just like in notepad.. because what i'm getting right now is when i open a *.ext file into my program with the "Open With..." prompt, it won't load the *.ext file that i opened with it..


2. i'm trying to make a simple antivirus software that could detect a file based on a file (db.txt) that contains the names of the harmful programs that it should find..

example:
let's say i clicked on the button "Scan File to Check if Threat" then i selected "C:/sample/some other folder/mysamplevirusprog.exe" how can i extract only the file name and extension (in this case "mysamplevirusprog.exe") only and WITHOUT the "C:/sample/some other folder/" part of the path included.. only the "mysamplevirusprog.exe"... i hope you're getting what i want to happen :?

Posted: Wed Feb 25, 2009 10:26 am
by Mark
Dear shadowslash,

File associations are not for beginners, but here's some info on the subject:

http://runrev.info/File%20Associations.htm

This is not about the command line but about setting registry keys. File associations don't depend on command line syntax.

If you look at the example I posted, you'll see that I already answered your questions, even though I didn't exactly understand what you want. To get the actualy file name, you can do this:

Code: Select all

set the itemDel to slash
put last item of myFilePath into myFileName
Best,

Mark

Posted: Wed Feb 25, 2009 11:37 am
by shadowslash
wow! this code really helped out a lot!

Code: Select all

set the itemDel to slash
put last item of myFilePath into myFileName
i got so many questions about runtime revolution that i don't know where to start, some of which is:

is it possible to load a SWF file into the program like embedding it?
if so, how do i do it?

i'm interested in knowing how to use file associations with my program because runtime revolution isn't my first program authoring tool.. i have tried others and i wanna know which would best be fit for me.. i already made other programs but it wasn't made in Runtime Revolution so it's kinda giving me a "culture shock" that runtime revolution's scripting is different... :cry:

Posted: Wed Feb 25, 2009 2:39 pm
by SparkOut
shadowslash wrote:1. i just want to know how to get the command line that will be passed to my program just in case somebody uses it.

example:
i made a text viewer / editor, if ever i'm going to associate my program to a certain file extension like *.ext, how do i get the command line that will be passed to it whenever a *.ext file will be opened with it.. in notepad, when you open a *.txt file with notepad, it loads the contents of the *.txt file right? that's what i wanna do with my program too, to be able to make my program detect which file was opened with it and then load the contents of that file into my program.. just like in notepad.. because what i'm getting right now is when i open a *.ext file into my program with the "Open With..." prompt, it won't load the *.ext file that i opened with it..
That sounds more like you want to make a standalone that will be launched with the *.ext loaded into it when you double-click the *.ext file than passing arguments from the command line?
You need to check up in the dictionary for $ (as a keyword) and "the params" and the startup and relaunch messages. The code below reacts to the startup message and deals with argument $1 passed when the *.ext file is double clicked. If there is more than one file selected which you want to open at once then the "relaunch" message will deal with each subsequent argument passed to it as a parameter in turn. The functions I have written to deal with putting it into "the next available field number" are just stuff to give a meaningful demonstration if you have several fields on the first card called Field1, Field2 and Field3, say. Once you have collected the arguments using the $1 argument passed to the startup handler and the parameter arguments passed to the relaunch handler you can do what you like with them (store them as custom properties of the stack, perform more processing, etc. Just remember that these messages will be active before the openCard and openStack messages are handled.)

Code: Select all

on startUp
   put fnReadFiles (fnCheckFile ($1)) into field "Field1" of card 1
end startup

on relaunch pParam
   local tNr
   if pParam is not empty then
      put fnReadFiles (fnCheckFile (pParam)) into field fnGetNextField ("Field")
   end if
end relaunch

function fnCheckFile pParam
   local tExpectedFileExts
   put "ext,eyt,ezt" into tExpectedFileExts
   --you can add/restrict filename extensions here as appropriate
   --I just made some rubbish up
   
   if there is a file pParam and char -3 to -1 of pParam is among the items of tExpectedFileExts then
      --this silently ignores any parameters that are not existing files with the right filename extension
      --you could do some more serious parameter checking as necessary
      return pParam
   end if
end fnCheckFile

function fnReadFiles pFile
   local tNr
   if pFile is not empty then
      return url ("file:" & pFile)
   end if
end fnReadFiles

function fnGetNextField pField
   --this is just a mockup function to get the next field to populate
   --you would probably do something different and more useful
   --with the returned file data
   local tNr, tField
   put 1 into tNr
   repeat until (field (pField & tNr) of card 1 is empty) or (tNr > 3)
      --just forces a max field count here
      --do some "proper" error trapping and useful checking
      --but then, you wouldn't be using the routine like this anyway
      --this is just to demonstrate handling the parameters, not a 
      --usable function
         add 1 to tNr
      end repeat
      return the long name of field (pField & tNr) of card 1
end fnGetNextField
The script is slightly different if you want to launch from the command line, as the dictionary will indicate, there are a few caveats, particularly on Windows.