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

How to create Sequence with multi lines in command-line? #74

Open
kth8384 opened this issue Mar 24, 2024 · 2 comments
Open

How to create Sequence with multi lines in command-line? #74

kth8384 opened this issue Mar 24, 2024 · 2 comments

Comments

@kth8384
Copy link

kth8384 commented Mar 24, 2024

Read from file ok.

But make the command in my application, then call _popen, the command string like this "diagon Sequence -style=Unicode -- "Renderer -> Browser: BeginNavigation()" -- "Browser -> Network: URLRequest()" -- "Browser <- Network: URLResponse()" -- "Browser <- Network: URLResponse()" -- "Renderer <- Browser: CommitNavigation()" -- "Renderer -> Browser: DidCommitNavigation()"", cannot work?

How to make the command string?

@ArthurSonzogni
Copy link
Owner

Hi!
The documentation says:

    * command_line: diagon Math -- 1+1/2
    * file        : diagon Math < filename
    * stdin       : diagon Math

So, you are missing the -- before your command line string.

You can try:

diagon Sequence -- "
  Browser -> Network: URLRequest() 
  Browser <- Network: URLResponse() 
  Browser <- Network: URLResponse() 
  Renderer <- Browser: CommitNavigation() 
  Renderer -> Browser: DidCommitNavigation()
"

or with a file inputed using <<EOF

diagon Sequence <<EOF
  Browser -> Network: URLRequest() 
  Browser <- Network: URLResponse() 
  Browser <- Network: URLResponse() 
  Renderer <- Browser: CommitNavigation() 
  Renderer -> Browser: DidCommitNavigation()
EOF

Output:

┌───────┐     ┌───────┐┌────────┐
│Browser│     │Network││Renderer│
└───┬───┘     └───┬───┘└───┬────┘
    │             │        │     
    │URLRequest() │        │     
    │────────────>│        │     
    │             │        │     
    │URLResponse()│        │     
    │<────────────│        │     
    │             │        │     
    │URLResponse()│        │     
    │<────────────│        │     
    │             │        │     
    │  CommitNavigation()  │     
    │─────────────────────>│     
    │             │        │     
    │DidCommitNavigation() │     
    │<─────────────────────│     
┌───┴───┐     ┌───┴───┐┌───┴────┐
│Browser│     │Network││Renderer│
└───────┘     └───────┘└────────┘

@kth8384
Copy link
Author

kth8384 commented Mar 26, 2024

the -- aren't missing.

Thank you very much!
Can you help me to check my source? I have try my best but cann't find the error of my program.

`#include

void cmdSystem(const std::string& cmd) {
system(cmd.c_str());
}

#if defined(WIN32) || defined(_WIN32)
std::string cmdPopen(const std::string& cmd) {
char buffer[1024] = { '\0' };
FILE* pf = NULL;
pf = _popen(cmd.c_str(), "r");
if (NULL == pf) {
std::cout << "open pipe failed" << std::endl;
return std::string("");
}
std::string ret;
while (fgets(buffer, sizeof(buffer), pf)) {
ret += buffer;
}
_pclose(pf);
return ret;
}
#else
void cmdPopen(const char *cmd, char *result) {
char buf_ps[1024];
char ps[1024] { 0 };
FILE *pf;
strcpy(ps, cmd);
if ((pf = popen(ps, "r")) != NULL) {
while (fgets(buf_ps, 1024, pf) != NULL) {
// every line of output
//std::cout << buf_ps << std::endl;
std::cout<< buf_ps<< std::endl;
strcat(result, buf_ps);
if (strlen(result) > 1024)
break;
}
pclose(pf);
pf = NULL;
} else {
std::cout << "popen " << ps << " error" << std::endl;
}
}
#endif

#if 1
int main() {
//std::string cmdLine(R"("echo Hello, World!")");

std::string cmdLine = "diagon Sequence -style=Ascii -- \"";
cmdLine.append("	Renderer -> Browser: BeginNavigation()\n");
cmdLine.append("	Browser -> Network: URLRequest()\n");
cmdLine.append("	Browser <- Network: URLResponse()\n");
cmdLine.append("	Browser <- Network: URLResponse()\n");
cmdLine.append("	Renderer <- Browser: CommitNavigation()\n");
cmdLine.append("	Renderer -> Browser: DidCommitNavigation()\n");
cmdLine.append("\"");

//cmdLine = { R"AAA(diagon Sequence < "seq.txt" )AAA" };

//cmdSystem("chcp 936");	// no return value
cmdSystem("chcp 65001");	// no return value
std::string result = cmdPopen(cmdLine);
std::cout << result << std::endl;

system("pause");

return 0;

}
#endif
`

the result is

`
Active code page: 65001
┌────────┐ ┌───────┐
│Renderer│ │Browser│
└───┬────┘ └───┬───┘
│ │
│BeginNavigation()│
│────────────────>│
┌───┴────┐ ┌───┴───┐
│Renderer│ │Browser│
└────────┘ └───────┘

Press any key to continue . . .

`

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

2 participants