You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

pandapipino

Beginner

  • "pandapipino" started this thread

Posts: 9

Date of registration: Sep 6th 2012

  • Send private message

1

Saturday, December 1st 2012, 2:35pm

How to open a file in linux?

Can you give me a sample working code for linux for opening files or executing commands in the terminal like "ls"?

Thank you

pandapipino

Beginner

  • "pandapipino" started this thread

Posts: 9

Date of registration: Sep 6th 2012

  • Send private message

2

Monday, December 3rd 2012, 2:30am

I would like to open a file in linux just like in windows:

Shell (myapp.exe)

How can I do this on linux?

Shell (linuxapp.sh) ?

Anyone?

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

3

Monday, December 3rd 2012, 2:35am

RE: How to open a file in linux?

Can you give me a sample working code for linux
I don't know what you mean. On Linux it works the same like on Windows.

Quoted

for opening files
denizunlu have posted at
[ http://www.jabaco.org/board/862-file-i-o.html ]
how to handle I/O.

Create a CommandButton called "Command1" and a RichTextBox called "RichTextBox1". Then this code works for Linux. It readss the hosts file and outputs it in the RichTextBox:

Jabaco Source

1
2
3
4
5
6
7
Public Sub Command1_Click()
  Dim mvFH As VBFileHandler
  Dim myTestFile As String
  mvFH=Open("/etc/hosts", vb#VBFileMode.Input)
  RichTextBox1.Text = mvFH.readAll
  mvFH.close
End Sub


Quoted

or executing commands in the terminal like "ls"?

Jabaco Source

1
2
3
Public Sub Command1_Click()
   Shell "/usr/bin/xman"
End Sub


Greatings
theuserbl

pandapipino

Beginner

  • "pandapipino" started this thread

Posts: 9

Date of registration: Sep 6th 2012

  • Send private message

4

Monday, December 3rd 2012, 4:07am

Thanks man!!!!!

this code works for me:

Quoted

Shell "/usr/bin/xman"

pandapipino

Beginner

  • "pandapipino" started this thread

Posts: 9

Date of registration: Sep 6th 2012

  • Send private message

5

Monday, December 3rd 2012, 5:25am

how can I open a .sh file?

Shell "./home/panda/myapp/start.sh"

doesn't seem to work

Shell "/home/panda/myapp/start.sh"


but it doesn't execute the file

This post has been edited 4 times, last edit by "pandapipino" (Dec 3rd 2012, 8:40am)


theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

6

Monday, December 3rd 2012, 2:06pm

On Windows (and Linux) you can also start Java-Programs:

Jabaco Source

1
Shell ("java -jar C:\Programme\Java\jdk1.7.0_07\demo\jfc\SwingSet2\SwingSet2.jar")


how can I open a .sh file?
What does the .sh file do?

Starts it a program with a window and so on?
Then you can write

Jabaco Source

1
Shell ("/bin/bash /home/panda/myapp/start.sh")

Gives it something out in commandline?
Then your program will be something bigger.

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Dim p As Process
p = Shell ("/bin/bash /home/panda/myapp/start.sh")
Dim input As java#io#InputStream
input = p.getInputStream

Dim data As Integer = input.read

While data <> -1
   Dim cdata As java#lang#Character
   cdata = Cast(data, java#lang#Character)      
   System.out.print(cdata)
   data = input.read
Wend
input.close
p.destroy


Greatings
theuserbl

pandapipino

Beginner

  • "pandapipino" started this thread

Posts: 9

Date of registration: Sep 6th 2012

  • Send private message

7

Monday, December 3rd 2012, 3:05pm

Thanks for your effort for replying my post, I really appreciate it.

Unfortunately it still doesn't work, I've tried all your examples its just that there were no errors but it still does not execute my .sh

my .sh file has this command inside:

Quoted

#!/bin/sh
python start.py
That code should launch a terminal window and execute my python script. Also my script works when typed manually in a terminal window.

I was also looking in my System Monitor to check if it was running in the background but no luck. It really does not execute it.

Opening a terminal window works with this code, but I don't know a way how to type a command on it:

Quoted

Shell "/usr/bin/x-terminal-emulator"
Typing:
Shell "usr/bin/x-terminal-emulator mycommand" does not work also.
Shell "usr/bin/x-terminal-emulator" & mycommand does not work too.

I hope you can help me more with this problem...

Thanks!

This post has been edited 3 times, last edit by "pandapipino" (Dec 3rd 2012, 3:19pm)


theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

8

Monday, December 3rd 2012, 4:14pm

Haven't much time at the moment.

But
my .sh file has this command inside:

Quoted

#!/bin/sh
python start.py

If it only starts python with a script, have you then tried out to start it direct in Jabaco?

Jabaco Source

1
Shell ("python start.py")


Greatings
theuserbl

PS: If the python-programs gives something out on commandline, you have again to use the extended version:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Dim p As java#lang#Process
p = Shell ("python start.py")
Dim input As java#io#InputStream
input = p.getInputStream

Dim data As Integer = input.read

While data <> -1
   Dim cdata As java#lang#Character
   cdata = Cast(data, java#lang#Character)      
   System.out.print(cdata)
   data = input.read
Wend
input.close
p.destroy


Or if you start your Jabaco-program from an file-manager like Konquerer, Nautilus, Dolphin or something else, then try the following, to see the commandline-output in an message-box:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Dim p As java#lang#Process
Dim s as String
p = Shell ("python start.py")
Dim input As java#io#InputStream
input = p.getInputStream

Dim data As Integer = input.read

While data <> -1
   Dim cdata As java#lang#Character
   cdata = Cast(data, java#lang#Character)      
   s = s + cdata.toString
   data = input.read
Wend
input.close
MsgBox s
p.destroy

This post has been edited 2 times, last edit by "theuserbl" (Dec 3rd 2012, 4:26pm)


pandapipino

Beginner

  • "pandapipino" started this thread

Posts: 9

Date of registration: Sep 6th 2012

  • Send private message

9

Tuesday, December 4th 2012, 2:25am

Yeah tried that also, no errors but it still does not execute any programs. I've tried many bunch of codes for shell but I'm also really out of ideas right now.

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

10

Tuesday, December 4th 2012, 7:55am

Yeah tried that also, no errors but it still does not execute any programs. I've tried many bunch of codes for shell but I'm also really out of ideas right now.


:(

On my computer it works without problems:


Greatings
theuserbl

This post has been edited 1 times, last edit by "theuserbl" (Dec 4th 2012, 8:06am)


pandapipino

Beginner

  • "pandapipino" started this thread

Posts: 9

Date of registration: Sep 6th 2012

  • Send private message

11

Tuesday, December 4th 2012, 2:37pm

Dude dude dude! it works!!

So I need to perform the command to load the my .jar file to the terminal... how dumb am I? so running it directly by right clicking and opening the file to java will not work.

This works for me:

Quoted

java -jar myjava.jar
Thanks man!!! this solved my problem. TYTYTY !!!! 8o :thumbup: :thumbsup:

Rate this thread
WoltLab Burning Board