Computer Science Canada

one small quick question

Author:  vicml21 [ Tue May 30, 2006 4:02 pm ]
Post subject:  one small quick question

i was wondering if anyone knew the code to open a file, using its default program. For example, open a text file using notepad, or open a music file using windows media player, like for Turing, it is:

code:
Sys.Exec("C:/File.txt")


or something like that. thanks in advance.

Author:  Tony [ Tue May 30, 2006 4:16 pm ]
Post subject: 

oddly enough it's [url=http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html#exec(java.lang.String)]exec()[/url]

Author:  vicml21 [ Tue May 30, 2006 5:19 pm ]
Post subject: 

hmm i looked it up a bit online too, and couldnt get it to run. Basically what im trying to do is run a *.asx file (playlist) in windows media player when the button "Flow" is pressed. It's all included in the zip (java files & the *.asx file im trying to play)

Author:  Tony [ Tue May 30, 2006 5:26 pm ]
Post subject: 

does the line you are trying to execute works from command-line console? (cmd)

Author:  vicml21 [ Tue May 30, 2006 5:30 pm ]
Post subject: 

no, it keeps telling me "command failed" (the message i get when it throws an exception, and doesnt run the file). Ive tried a couple of different ways to use the code, but none of them that I've found worked.

Author:  rizzix [ Tue May 30, 2006 8:35 pm ]
Post subject: 

I believe to get this functionality in windows (through the command line) you need to execute "start", as in "start blabla.asx"

Author:  vicml21 [ Tue May 30, 2006 9:50 pm ]
Post subject: 

hmm.. im not sure what you mean. like if the file was in the same folder, and i wanted to open Flow.asx in windows media player, what would the code look like?

Author:  Tony [ Tue May 30, 2006 9:56 pm ]
Post subject: 

http://support.microsoft.com/KB/241422 wrote:

Mplayer2.exe /play C:\location\Flow.asx

Author:  rizzix [ Tue May 30, 2006 10:30 pm ]
Post subject: 

Or as mentioned before (but I haven't tested it)
code:
start ./Flow.asx

Author:  vicml21 [ Tue May 30, 2006 11:46 pm ]
Post subject: 

well the "start ./Flow.asx" works in cmd to run the file. but i was wondering.. how would i use this in java program?

Author:  [Gandalf] [ Wed May 31, 2006 9:42 pm ]
Post subject: 

Anything you can type in the command prompt will work with the exec() method Tony posted.

Author:  vicml21 [ Fri Jun 02, 2006 12:19 am ]
Post subject: 

well i just got it to open regular *.exe's, regular websites (on my comp anyway), and *.bat files. I could use the *.bat files to run the cmd commands, but if anyone else knows anyway to run any random file (with no specific extension, not just bat & exe), i would greatly appreciate it!

Author:  rizzix [ Fri Jun 02, 2006 11:26 am ]
Post subject: 

I thought start <file> was supposed to do just that. It should open the <file> with the default application.


: