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

ProcessRunner.GetProcessOutputAsync is not working #14

Closed
edmundormz opened this issue Feb 2, 2017 · 2 comments
Closed

ProcessRunner.GetProcessOutputAsync is not working #14

edmundormz opened this issue Feb 2, 2017 · 2 comments

Comments

@edmundormz
Copy link

edmundormz commented Feb 2, 2017

This is the code being used (From RaspberryIO Playground):

` public bool SetupWirelessNetwork(string adapterName, string networkSsid, string password = null)
{
var payload = "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev\nupdate_config=1\n";

        payload += string.IsNullOrEmpty(password) ?
            $"network={{\n\tssid=\"{networkSsid}\"\n\t}}\n" :
            $"network={{\n\tssid=\"{networkSsid}\"\n\tpsk=\"{password}\"\n\t}}\n";

        try
        {
            File.WriteAllText("/etc/wpa_supplicant/wpa_supplicant.conf", payload);
            ProcessRunner.GetProcessOutputAsync("ifconfig >> /home/pi/ifconfig.txt");
            //ProcessRunner.GetProcessOutputAsync("sudo pkill -f wpa_supplicant >> /home/pi/Documents/kill_wpa.txt");
            //ProcessRunner.GetProcessOutputAsync("sudo wpa_supplicant", $"-B -D wext -i {adapterName} -c /etc/wpa_supplicant/wpa_supplicant.conf >> /home/pi/Documents/run_wpa.txt");
        }
        catch
        {
            return false;
        }

        return true;
    }`

After a while testing on raspberry, realized the "ProcessRunner.GetProcessOutputAsync" does nothing at all. Used the line "ProcessRunner.GetProcessOutputAsync("ifconfig >> /home/pi/ifconfig.txt");" to be sure and it did not created any file, but command worked on command line.

Am I using this the wrong way?

@mariodivece
Copy link
Member

for starters, an async operation has to be awaited or it's result retrieved in order for it to do anything at all... NOOBZ

@edmundormz
Copy link
Author

You´re ritght
My mistake
Fixed like this:
ProcessRunner.GetProcessOutputAsync("pkill", "-f wpa_supplicant").Wait();

@geoperez geoperez closed this as completed Feb 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants