• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jcifs smbfile how to execute file

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an xp box with file sharing open and can access files through the LAN, but how do I do this in Java?

currently I have:


which works perfectly in allowing me to list the file, but say the file is some movie.avi, or a program.exe, how do I tell Java to execute that file using the default program?
Basically what I'm looking for is exactly like:

Desktop.getDesktop().open(new File("C:\..."))

Only this time I'm using SmbFile to allow credentials (and thus log into a share server).
Is there a SmbDesktop or something?

It seems like this should be very easy: I have access to the file... all I want to do is run it.

~Thanks in advance!

[edit: this is the exact same problem as https://coderanch.com/t/509245/Servlets/java/open-File-server-JCIFS-or#2301848
only the fix given is to run a command line which is only a workaround]
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Zachary Wilson wrote:It seems like this should be very easy: I have access to the file... all I want to do is run it.



Let's clarify that "easy" question: It isn't "you" which has access to the file, it's your Java code. And it isn't "you" which would run it, it would be the operating system.

Now that we have a clearer (but less "easy") question, we have a clearer answer. Your Java code has access to the file, but the operating system doesn't. But you want the operating system to run the file. Does that help?
 
Zachary Wilson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I need to find a way to transfer access from my java file to the current operating system, or have the operating system read through the java; I have no idea how to do that: I'm thinking read each byte and transfer it somehow, but as far as the actual code to accomplish this: I do not know.

Thanks for the guidance!
 
Ranch Hand
Posts: 147
Eclipse IDE Tomcat Server Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you might be able to try is using Runtime.exec(...) to request the operating system execute or open the file. However, Runtime.exec has a laundry list of issues itself. See http://www.javaworld.com/jw-12-2000/jw-1229-traps.html for a short list; I am sure others on the forum will also pipe in on the evils of Runtime.exec(...)
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, if you copied the file from its remote location to some place in the same computer where the code is running, you could then ask the operating system to open it.
 
Zachary Wilson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to stream the file? For example, when I tell xp to open a file in //sharename/filename.exe , it reads it from the source rather than copying it to my local computer (given the file can be a large movie, yet it still begins playing it instantly)

In using Runtime.exec() I need to provide credential to execute any file, and I'm trying to avoid a "net use \\192...." as it is windows specific.

It would be beautiful if there was a Desktop.getDesktop().open(SmbFile).

Right now I have:

which is compatible with Java.io, and I can read the file line by line, but how to I execute it with a default editor/program ?
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Zachary Wilson wrote:Is it possible to stream the file?



I suppose if "executing the file" supported some kind of streaming mode, and your program could somehow insert itself into the "executing the file" process, then it might be possible. But that would involve modifying the operating system to call your class to "execute" the file. So no, I don't think that's too likely. Besides which it would be operating-system specific, and you said you didn't want that.

Remember, when you call Desktop.getDesktop().open(X), you're just telling the O/S to open the file X. Your Java program isn't anywhere in the picture when that opening takes place.
 
Zachary Wilson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:
Remember, when you call Desktop.getDesktop().open(X), you're just telling the O/S to open the file X. Your Java program isn't anywhere in the picture when that opening takes place.



Right, but when I call Desktop.getDesktop().open(X), X is a Java.io.File object that is being executed by the O/S. Is there not a method to invoke the O/S to open/execute with credentials?

I have an SmbFile object, now all I want is for that object to be executed by the O/S.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Zachary Wilson wrote:Right, but when I call Desktop.getDesktop().open(X), X is a Java.io.File object that is being executed by the O/S.



You're skipping the important details again. Sure, you pass a File object to that method. But of course the O/S function which opens a file has no idea what a java.io.File object is. Internally the "open" method must get the path to the file -- which is just a string -- and pass that to the O/S function. The O/S function doesn't use any code and doesn't know anything about any Java objects. Any theory which has O/S code knowing anything about Java is an incorrect theory.
 
Zachary Wilson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So put bluntly: it's not possible to run a file as if I were exploring the share server via windows? (Without copying the entire contents of the file onto the local machine, and then running).
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic