PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, September 10, 2022

[FIXED] How to get a list of system users in vlang?

 September 10, 2022     account, cross-platform, vlang     No comments   

Issue

I am trying to list all the system users, I know that on Linux I could use awk -F: '{ print $1 }' /etc/passwd and on Windows I could use wmic useraccount get name but I was wondering if there was function in V that would be better suited for it and didn't require different commands for Linux and Windows.


Solution

EDIT: You can now use fn user_names() ?[]string from the os module in order to get the names of users on the system.

There currently is now way to get a list of users on the system. However you can you compile time if statements to execute the commands you referred to above.

import os

fn main() {
    $if windows {
        result := os.execute('wmic useraccount get name')?
    } $else $if linux {
        result := os.execute('awk -F: "{ print $1 }" /etc/passwd')?
    } $else {
        println('unsupported os')
    }
    // do something with result
}


Answered By - Adam Oates
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing