在控制台应用中获取环境变量

时间:2016-11-20 14:50:34

标签: c# batch-file environment-variables

我需要分析我的环境变量值(COPYCMD) 批次:

SET COPYCMD = /-y
SUPERCOPY.exe someFile.some someDirectory

SUPERCOPY - 是我的实用工具

SUPERCOPY代码:

...
string environmentVar = Environment.GetEnvironmentVariable("COPYCMD");
...

此字符串始终返回null。 我也试过另一种方式:

IDictionary environment = Environment.GetEnvironmentVariables();
if ((environment["COPYCMD"] as string).ToUpper() == "/-Y")
{
    DoSomething();
}

这种方式也不起作用

1 个答案:

答案 0 :(得分:1)

我认为问题是你的环境变量名称中有一个尾随空格......

尝试:

import UIKit
import MultipeerConnectivity

class ViewController: UIViewController, MCNearbyServiceBrowserDelegate,      MCNearbyServiceAdvertiserDelegate {


let browser = MCNearbyServiceBrowser(peer: MCPeerID(displayName: "iOS Device"), serviceType: "example-test")
let peerID = MCPeerID(displayName: "iOS Device")
let advertiser = MCNearbyServiceAdvertiser(peer: MCPeerID(displayName: "iOS Device"), discoveryInfo: nil, serviceType: "example-test")



override func viewDidLoad() {
    super.viewDidLoad()
    advertiser.delegate = self
    advertiser.startAdvertisingPeer()
    browser.delegate = self
    browser.startBrowsingForPeers()
}

func browser(_ browser: MCNearbyServiceBrowser, lostPeer peerID: MCPeerID) {

}

func browser(_ browser: MCNearbyServiceBrowser, didNotStartBrowsingForPeers error: Error) {

}

func browser(_ browser: MCNearbyServiceBrowser, foundPeer peerID: MCPeerID, withDiscoveryInfo info: [String : String]?) {
    print("FOUND!!!")
}

func advertiser(_ advertiser: MCNearbyServiceAdvertiser, didNotStartAdvertisingPeer error: Error) {

}

func advertiser(_ advertiser: MCNearbyServiceAdvertiser, didReceiveInvitationFromPeer peerID: MCPeerID, withContext context: Data?, invitationHandler: @escaping (Bool, MCSession?) -> Void) {

}


 }