Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.ls() can't open dir #848

Closed
JasonHonor opened this issue Jun 30, 2019 · 6 comments
Closed

os.ls() can't open dir #848

JasonHonor opened this issue Jun 30, 2019 · 6 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@JasonHonor
Copy link

JasonHonor commented Jun 30, 2019

V version:
0.1.10
OS:
CentOS 7.6.1810

What did you do?
using os.ls() to list files of the current directory.

import os

fn main()
{
    //get the type of os
    ostype:=os.user_os()
    println('OsType:$ostype')

    hostname:=os.exec('hostname')
    println('Hostname:$hostname')

    //get home dir of current user
    home:=os.home_dir()
    println('HomeDir:$home')

    //get the current executable file path.
    exepath:=os.getexepath()
    println('ExePath:$exepath')

    pwd:=os.exec('pwd')
    println('CurrentDir:$pwd')

    //execute a command and fetch result string.
    uname:=os.exec('uname -ra')
    println('Uname:$uname')

    println(os.ls(pwd))
}

What did you expect to see?
[user@centos os_info]$ ls
os_info os_info.v

What did you see instead?
[user@centos os_info]$ v run os_info.v |more
OsType:linux
Hostname:centos
HomeDir:/home/user/
ExePath:/home/user/code/v/examples/os_info/os_info
CurrentDir:/home/user/code/v/examples/os_info
Uname:Linux centos 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
ls() couldnt open dir "/home/user/code/v/examples/os_info"
[]
============ running os_info ============

@JasonHonor JasonHonor added the Bug This tag is applied to issues which reports bugs. label Jun 30, 2019
@medvednikov
Copy link
Member

Can you run ls /home/user/code/v/examples/os_info in your terminal?

@JasonHonor
Copy link
Author

yes, the result as following:

[user@centos os_info]$ ls /home/user/code/v/examples/os_info
os_info  os_info.v

@medvednikov
Copy link
Member

And now try

import os
fn main() {
  files := os.ls('/home/user/code/v/examples/os_info')
  println(files)
}

@JasonHonor
Copy link
Author

Successfully it run.

[user@centos os_info]$ v run os_try.v
============ running os_try ============
["os_info.v", "os_info", "os_try.v", "os_try"]

@medvednikov
Copy link
Member

Ok I think I know what it is:

pwd:=os.exec('pwd')

You need to call .trim_space()

But it's much better to use a function:

pwd:=os.getwd()

@JasonHonor
Copy link
Author

ok, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

2 participants