0

I try to send second command to cmd. in cmd maybe i should do this

Microsoft Windows [Version 10.0.14986]
(c) 2016 Microsoft Corporation. All rights reserved.
C:\WINDOWS\system32>D:
D:\>set /p a=Write a text :
Write a text : This is a sample
D:\>echo %a% > sample.txt
D:\>type sample.txt
This is a sample
D:\>

Change to drive D > set a variable > write the answer > write it to a file and read it.
inline code is :
cmd.exe /c "D: & set/p a=write a text : & echo %a% > sample.txt & type sample.txt & pause"

its sucks when i want to use it in VB Script. while i try to get command, i will take it out to file. But how if there is a input request like :

Press any key to continue...
Are you sure you want to continue? (Y/n)
Ping an IP : (xxx.xxx.xxx.xxx)

and when i send command to it. it will auto exit if its finish the task like

CreateObject("WScript.Shell").run "cmd.exe /c ping google.com > myfile.txt
'After finish pinging it will auto exit.

And my question are, how i send input to cmd. And how i KEEP the cmd still live
Any ideas?
Oh ya. I wont to use batch-file to execute it.

user692942
  • 14,779
  • 6
  • 66
  • 157
  • Possible duplicate of [How to keep the vb-script command window open during execution](http://stackoverflow.com/questions/7526598/how-to-keep-the-vb-script-command-window-open-during-execution) – user692942 Jan 22 '17 at 09:49

2 Answers2

0

Pause and cmd /k should do your work.

See the LINK for reference.

IN VBA, you can do something like this:

Set objShell = CreateObject(“Wscript.Shell”)

objShell.Run(“%comspec% /k ipconfig /all”)

Here is another VBscript reference

Community
  • 1
  • 1
Ranadip Dutta
  • 7,709
  • 2
  • 20
  • 33
  • Technically it just make the cmd keep alive and cannot send any command to it. Then, My question is how i send the second command or send input for input request like `Press any key to continue...` / `Are you sure you want to continue?(Y/n)` `IP : (xxx.xxx.xxx.xxx)` without `&` or `-F` `/y` parameter – Farhan M Sabran Jan 21 '17 at 14:53
  • @FarhanMSabran : I recommend using the `/Q` option instead, but the pipe technique might be important if you ever run into a command that does not provide an option to suppress confirmation messages. – Ranadip Dutta Jan 22 '17 at 14:17
0

One possibility would be to use pipe communication between your VB6 process and your cmd process. Please have a look on below Windows API functions:

  1. CreatePipe (kernel32)
  2. CreateProcess (kernel32) => cmd without /c flag
  3. ReadFile/WriteFile on pipe handles to read/write cmd input/ouput

Creating a Child Process with Redirected Input and Output

Jeandey Boris
  • 669
  • 4
  • 8