Sending command to console application

Posts 1–11 of 11 · Page 1 of 1
Sending command to console application
Hi,
I've created a console application using C++, Is there any way to send for example textbox text to the console?
I tried
Code:
Shell("Console.exe /k" + textbox1.text)
but didn't work, only opens the console without inserting the command/text.
Any help is appreciated, Thanks.
Code:
Process.Start("Console.exe", "/k " & TextBox1.Text);
Quote Originally Posted by Biesi View Post
Code:
Process.Start("Console.exe", "/k " & TextBox1.Text);
Same results, nothing.

Quote Originally Posted by ERGaergaergaergaergearg View Post
Wait, just to make clear.

You created a C++ Console Application. But you wanna insert commands to cmd using TextBox?

Does Console application have a textbox?
Did not know that.
I didn't even mention cmd.
I meant, I created a C++ console application & want to send a command from my VB.NET form to it (the console).
Wait, just to make clear.

You created a C++ Console Application. But you wanna insert commands to cmd using TextBox?

Does Console application have a textbox?
Did not know that.
Maybe it's your C++ Console then
Quote Originally Posted by Biesi View Post
Maybe it's your C++ Console then
It's a normal console, why would it be the issue.
@Mayion Shell("Console.exe /k" + textbox1.text) what is the argument type for the Shell() function, what data type?

And in the C++ program, where it gets the arguments..what data type is this?

If you don't know, maybe it's worth investigating.

If it was me, I'd add some code to the beginning of main() (ie. don't let your normal code run) in the C++ app and MessageBox() the first argument passed to it..at least then you'll know when the C++ side thinks it got an argument passed in. Then try things on the vb side which possibly send different strings (see my first 2 questions).

The function mentioned by Biesi should (...does) work, must be your console app.

Post code...pretty much always --> use [ s p o i l e r = zCode ] ... [ / s p o i l e r ] if you don't want it to take up a lot of space.

edit: change char to wChar on your C++ side because the vb-side is sending a utf16 string, and the console is expecting 1-byte ascii? Or maybe it's the opposite? I haven't used the Shell() function, but I promise the one mentioned by Biesi works.. I guess give us more details like OS,cpu_size/compiled as x86/x64, which version of V$. and POST CODE.
edit2: Biesi noticed --> OP, Did you mean to put a space after the "/k" or not? Maybe this is causing the C++ program to act like it didn't get the argument (which is why I mention the MsgBox() idea).
Quote Originally Posted by abuckau907 View Post
Post code...pretty much always --> use [ s p o i l e r = zCode ] ... [ / s p o i l e r ] if you don't want it to take up a lot of space.
I'm using a really simple code of Crosshair (I think you already know it).
 
Code

bool crosshairon=false;
HDC ragedc = NULL;
int crosshairsize=0;
int cx=0;
int cy=0;


void CrossThread(void)
{
while(1)
{
if(GetAsyncKeyState(VK_NUMPAD1)&1)
{
crosshairon=!crosshairon;
ragedc = GetDC(HWND_DESKTOP);
cx=GetSystemMetrics(SM_CXSCREEN)/2-((crosshairsize-1)/2);
cy=GetSystemMetrics(SM_CYSCREEN)/2-((crosshairsize-1)/2);
}
Sleep(1);
}
}

int main()
{
SetConsoleTitle(L"TTLE");
cin>>crosshairsize;
if(crosshairsize%2==0) //check if its even
{
crosshairsize+=1; //if it is add 1
}
cout<<"\n";
CreateThread(0,0,(LPTHREAD_START_ROUTINE)CrossThre ad,0,0,0);
while(1)
{
if(crosshairon==true)
{
for(int i=0;i<crosshairsize;i++)
{
SetPixel(ragedc, cx+i, cy+((crosshairsize-1)/2), RGB(255,0,0));
SetPixel(ragedc, cx+((crosshairsize-1)/2), cy+i, RGB(255,0,0));
}
}
Sleep(1);

The thing I want is, to send the CRHair size & press enter.
cin>>crosshairsize;

you expect this to input the first argument into crosshairsize?


edit: does that actually work??? Can you start the program from command line and successfully pass in an argument?
And what does the /k do? I assumed it was something to do specifically with the shell() function ..looks like your program isn't using it..?
Quote Originally Posted by abuckau907 View Post
cin>>crosshairsize;

you expect this to input the first argument into crosshairsize?


edit: does that actually work??? Can you start the program from command line and successfully pass in an argument?
And what does the /k do? I assumed it was something to do specificly with the shell() function ..looks like your program isn't using it..?
It worked after removing
cin>>crosshairsize;
& editing
if(crosshairsize%2==0)
Thanks but why did it work after removing the cin>>crosshair?
because crosshairsize is initialized to 0 and then you +1'd it..crosshair size will always be 1? lol :/

edit:
learn how to make your main() function take 2 arguments (an 'argument count' integer,and a pointer to a character array). That's how everyone else does command like arguments.

How you not gonna answer my questions..I even bolded them so you'd notice : ( Are you actively trying to avoid learning?

--Apparently you understand the GetAsyncKey() thing.... just default the crosshairsize to 1 like you're already doing and then add a key for "make larger" and "make smaller" : p probably easiest solution for you.
Posts 1–11 of 11 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us