Can I stop Visual Studio URL decoding Command Arguments in Debug mode?

和自甴很熟 提交于 2021-01-29 05:32:59

问题


If I set my program to echo command arguments and run in Visual Studio debugger with Command Arguments "https%3a%2f%2fas" it will echo 'https://as'

However, if I run from the command line 'myprog.exe https%3a%2f%2fas' then it will echo 'https%3a%2f%2fas'

Why is it handling this differently, and how can I stop it? I have to pass in an argument that is URL encoded and it needs to not be interpreted by Visual Studio first.

Program is C++ and it's Visual Studio 2017 if that is any help.


回答1:


Can I stop Visual Studio URL decoding Command Arguments in Debug mode?

Sorry but I'm afraid the answer is negative. This issue does exist after my test, and as far as I know there is no option in VS now can turn off or control this behavior. For this, I suggest you can Go Help=>Send Feedback=>Report a problem in VS to report this issue to product team.

I have to pass in an argument that is URL encoded and it needs to not be interpreted by Visual Studio first.

And since it works well in command-line. So what you need is to get the UrlEncode format string during the VS debug process in your development. For this you can try:

1.Add some code before where you need the real argument to UrlEncode the argv[1](I think it's https://as). About how to do UrlEncode see this issue.

2.Set the argument in this way, set https% 3a% 2f% 2fasas the argv[1] instead of https%3a%2f%2fas in project properties, then add code to judge if it contains space, if true=>write code to remove the space in it and get a new string you want (https%3a%2f%2fas)

3.Configure your custom Argument file:

1# In vs, right-click the project=>add a Text.txt file into project.

2# Set the only argument in this as Text.txt.

Then the content of your Text.txt is the collection of your custom arguments. For example:

In the line1 of Text.txt file is https%3a%2f%2fas, line2 is test, line3 is...

3# Then you can use code like this:

#include "pch.h"
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main(int argc, char* argv[])
{
    ifstream infile(argv[1]); //open the file

    string MyArgus[10]; //create my alternative argus
    MyArgus[0] = argv[0]; //let the first argu of Myargus=original vs argu[0]
    if (infile.is_open() && infile.good()) {
        cout << "File is open."<<endl;
        string line = "";

        int num = 1;
        while (getline(infile, line)) {
            MyArgus[num] = line;
            num++;
        }
    }
    else {
        cout << "Failed to open file..";
    }

    cout << MyArgus[0]<<endl; // projectName.exe always
    cout << MyArgus[1]<<endl; // https%3a%2f%2fas
    cout << MyArgus[2]<<endl; // test
    return 0;
}

So you can write arguments in this way in Text.txt file to set your custom arguments to avoid the auto UrlDecode in VS.

Hope it helps:)



来源:https://stackoverflow.com/questions/56837801/can-i-stop-visual-studio-url-decoding-command-arguments-in-debug-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!