473,382 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

writing in notepad through through shell command

Hi;

I m using following code for writing system IP in notepad from shell command

shell("ipconfig > c:\ipfile.txt")

but it do nothing( no errors comes also)

please solve this problem

Thanx
Ravi
Sep 29 '08 #1
19 3922
FishVal
2,653 Expert 2GB
Hello, Ravi.

I'm not sure whether stdout could be directed to text file using command line parameter, but you can easily get it by Access (did you mean this ?) application. Read the following - Waiting for Shell to Finish.

Regards,
Fish.
Sep 29 '08 #2
ADezii
8,834 Expert 8TB
Something very similar can easily be implemented within a Batch File, and even opened within Access if you so desire:
Expand|Select|Wrap|Line Numbers
  1. @Echo Off
  2. cls
  3. IPConfig.exe > C:\Windows\IP_Config.txt
  4. Notepad.exe C:\Windows\IP_Config.txt
Sep 29 '08 #3
NeoPa
32,556 Expert Mod 16PB
Firstly, using parentheses to surround the Shell() parameters is only correct if you Call the function :
Expand|Select|Wrap|Line Numbers
  1. Call Shell("IPConfig >C:\IPFile.Txt")
Also, check out ShellWait() Function for synchronous execution of commands.
Sep 29 '08 #4
ADezii
8,834 Expert 8TB
Firstly, using parentheses to surround the Shell() parameters is only correct if you Call the function :
Expand|Select|Wrap|Line Numbers
  1. Call Shell("IPConfig >C:\IPFile.Txt")
Also, check out ShellWait() Function for synchronous execution of commands.
That's not exactly True, is it NeoPa? Since the Shell Function returns a Variant (Double) representing the Program's task ID if successful, otherwise 0. Call can only be used on a Function when you wish to ignore the Return Value. All this is applicable especially in the Thread's context, otherwise, aside from opening the actual Text File, how would you know if it executed correctly?
Expand|Select|Wrap|Line Numbers
  1. Dim RetVal As Variant
  2. RetVal = Shell("C:\WINDOWS\SYSTEM32\CALC.EXE", vbNormalFocus)
  3.  
  4. If RetVal <> 0 Then
  5.   MsgBox "Shell executed successfully!"
  6. Else
  7.   MsgBox "Command did not execute"
  8. End If
Sep 29 '08 #5
NeoPa
32,556 Expert Mod 16PB
You're absolutely right ADezii.

What I should have said is that using parentheses to surround the Shell() parameters is only correct if you are using the function as a function rather than as a subroutine. That is to say that a value is returned. This can be done by assigning the value to something, using it in some evaluation or using Call to state explicitly to ignore the resultant value.

Functions are allowed (VBA is rather stupid that way) to be called as subroutines in code. This has a similar effect to using Call but it is less obvious what the coder is dealing with. The parentheses are not used whan calling a function as a subroutine.
Sep 29 '08 #6
FishVal
2,653 Expert 2GB
Just out of curiosity.

Did anybody get that
Expand|Select|Wrap|Line Numbers
  1. IPConfig >C:\IPFile.Txt
  2.  
work as expected?
Sep 29 '08 #7
NeoPa
32,556 Expert Mod 16PB
I don't understand the question Fish?

What are you not sure about?
Sep 29 '08 #8
FishVal
2,653 Expert 2GB
I don't understand the question Fish?

What are you not sure about?
Does that put stdout stream to text file?
That is basically what I'm not sure about.

Did anybody get IPConfig output to text file via Shell() function or even Start>Run... ?
Sep 29 '08 #9
NeoPa
32,556 Expert Mod 16PB
Aah. I see you mean did anybody get to work, the code :
Expand|Select|Wrap|Line Numbers
  1. Call Shell("IPConfig >C:\IPFile.Txt")
Trying to work out what you were asking I tried it and it didn't work. The redirection characters' functionality must be provided by the interpreter. I will work out a replacement version that should invoke the standard interpreter and work. Give me a minute.
Sep 29 '08 #10
NeoPa
32,556 Expert Mod 16PB
Did anybody get IPConfig output to text file via Shell() function or even Start>Run... ?
No. It doesn't work from either method.

I'm just preparing a version that should work.
Sep 29 '08 #11
FishVal
2,653 Expert 2GB
From command line it works well, BTW. From batch file too. ADezii has made a good point.
Sep 29 '08 #12
NeoPa
32,556 Expert Mod 16PB
The following code can be run from the Immediate Pane :
Expand|Select|Wrap|Line Numbers
  1. strCmd = """%C"" /C IPConfig >C:\IPFile.Txt" : _
  2. strCmd = Replace(strCmd, "%C", Environ("ComSpec")) : _
  3. Call Shell(strCmd)
This is a bit different from the code you would use if you want it in a module, but the basics are all there.
Sep 29 '08 #13
ADezii
8,834 Expert 8TB
The following code can be run from the Immediate Pane :
Expand|Select|Wrap|Line Numbers
  1. strCmd = """%C"" /C IPConfig >C:\IPFile.Txt" : _
  2. strCmd = Replace(strCmd, "%C", Environ("ComSpec")) : _
  3. Call Shell(strCmd)
This is a bit different from the code you would use if you want it in a module, but the basics are all there.
@NeoPa & FishVal, I was able to handle the entire process within Access, namely:
  1. Execute the Batch File (IP.Bat) listed below:
    Expand|Select|Wrap|Line Numbers
    1. @echo off
    2. cls
    3. IPConfig.exe > C:\Windows\IP_Config.txt
  2. Display the results of IP_Config.txt in a Text Box [txtIP]:
    Expand|Select|Wrap|Line Numbers
    1. Dim blnRetVal As Boolean
    2. Dim strTextLine As String
    3. Dim strBig As String
    4. Const con_BATCH_FILE_PATH As String = "C:\IP.bat"
    5. Const con_Text_FILE_PATH As String = "C:\Windows\IP_Config.txt"
    6.  
    7. blnRetVal = Execute_Program(con_BATCH_FILE_PATH, "", "")
    8.  
    9. Open con_Text_FILE_PATH For Input As #1
    10.  
    11. Do While Not EOF(1)             'Loop until end of file.
    12.   Line Input #1, strTextLine    'Read line into variable.
    13.   If Len(strTextLine) > 0 Then
    14.     strBig = strBig & Trim$(strTextLine) & vbCrLf
    15.   End If
    16. Loop
    17. Close #1                        'Close file.
    18.  
    19. Me![txtIP] = strBig             'Assign String to Text Box
  3. OUTPUT in txtIP:
    Expand|Select|Wrap|Line Numbers
    1. Windows IP Configuration
    2. Ethernet adapter Local Area Connection:
    3. Connection-specific DNS Suffix  . :
    4. IP Address. . . . . . . . . . . . : 192.168.1.102
    5. Subnet Mask . . . . . . . . . . . : 255.255.255.0
    6. Default Gateway . . . . . . . . . : 192.168.1.1
  4. Just let me know if this is a little extreme, I do this occasionally! (LOL)! I'll Post the Declarations and Function only if anyone is actually interested.
Sep 30 '08 #14
FishVal
2,653 Expert 2GB
Here is an example using Windows Script Host Model library.

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnIPConfig_Click()
  2.  
  3.     Dim objWshShell As New IWshRuntimeLibrary.WshShell
  4.     Dim objApp As IWshRuntimeLibrary.WshExec
  5.  
  6.     Set objApp = objWshShell.Exec("IPConfig")
  7.     While objApp.Status = WshRunning
  8.     Wend
  9.     Me.txbStdOut = objApp.StdOut.ReadAll
  10.  
  11.     Set objApp = Nothing
  12.     Set objWshShell = Nothing
  13.  
  14. End Sub
  15.  
Sep 30 '08 #15
NeoPa
32,556 Expert Mod 16PB
Hi
it is also not creating IPFile in c:
This was found in a report from the OP. It was submitted roughly 5 1/2 hours ago (before this post).
Sep 30 '08 #16
NeoPa
32,556 Expert Mod 16PB
Unfortunately, as there is no reference to what you're talking about (there are after all, many suggestions in this thread), it's hard to know how to respond.

@ADezii & Fish
Although these ideas may be interesting in their own right, as the (fairly) simple command can be run directly from within Access it does seem a little overkill.

It does make me wonder if what I posted was understood clearly. Maybe I overcomplicated it somewhat, but I wanted a copy / pastable solution that would enable anyone to test the theory for themselves. It certainly produces the required results (Referring to post #13).
Sep 30 '08 #17
ADezii
8,834 Expert 8TB
Unfortunately, as there is no reference to what you're talking about (there are after all, many suggestions in this thread), it's hard to know how to respond.

@ADezii & Fish
Although these ideas may be interesting in their own right, as the (fairly) simple command can be run directly from within Access it does seem a little overkill.

It does make me wonder if what I posted was understood clearly. Maybe I overcomplicated it somewhat, but I wanted a copy / pastable solution that would enable anyone to test the theory for themselves. It certainly produces the required results (Referring to post #13).
Perhaps I was the one who misinterpreted the OP's request. Redirecting the Output of the IPConfig Command was only half the equation, displaying the Output within the context of Access was the other. That's why the logic in Post Numbers 3 and 14. Oh well, it wasn't the first, and it surely won't be the last time, that I was wrong (LOL).
Sep 30 '08 #18
NeoPa
32,556 Expert Mod 16PB
Not at all ADezii. You may well be right. I simply interpreted the "in Notepad" as meaning in a (the) format that Notepad uses (IE .Txt).

Your psychic powers may well be more sensitive than mine on this issue ;)
Sep 30 '08 #19
NeoPa
32,556 Expert Mod 16PB
Ravi,

I notice you have just tried again to post the same message as you tried before. When you want to post you need to click on the Reply button rather than the Report one.

Reporting merely sends a private message to the moderators letting them know you feel something is wrong with that post.

I hope you are more successful in future.
Sep 30 '08 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Trevor Fairchild | last post by:
I need to open an html document in notepad and save it using ANSI encoding. I can do this manually using notepad and File/Save-as, but is there a way to do this from VB. I can open a specific...
1
by: Roger | last post by:
I've got some MS-windows (XP only?) related questions; hopefully someone can give me some advise. 1) Is there some way to make notepad to become the front window when it is started from within...
17
by: George | last post by:
Newbie question: I'm trying to lauch Notepad from Python to open a textfile: import os b1="c:\test.txt" os.system('notepad.exe ' + b1) However, the t of test is escaped by the \, resulting...
5
by: L337Hax0r | last post by:
for my operating systems design class i am supposed to write a shell in c. i have no idea where to start and our teacher hasn't given us much info. anyone know of any good tutorials?
7
by: Lumpierbritches | last post by:
Thank you in advance for any and all assistance. It is greatly appreciated. I would like a command button in VB.Net 2002 to open a text file, then to allow text from a textbox on the current form...
7
by: kisshug | last post by:
hi i'm working on project.in that i have 2 call notepad.exe. i want to know how to call notepad.exe from a c program in unix environment -- kisshug Message posted via ...
5
by: Mark M | last post by:
I am attempting to use a third party command-line utility (WinDump.exe) to capture network traffic for perfromance analysis. This utility when launched captures network traffic until Ctrl-C is...
2
by: Bob | last post by:
Looking at shell command I don't see how I can specify the filename to open. I need to launch notepad AND automatically open an existing file. Using VB 2005. Any help would be greatly...
35
by: jleslie48 | last post by:
I've written a cgi program in C using the borland 5.5 free compiler, and it runs just fine on an Apache server. My only issue is if I issue some system calls the cgi suspends until the call...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.