Syntax error in line 1

I am getting Syntax error in line 1 near a (weird symbol) digraph. I am trying to turn this info into a PNG. please help.

digraph processtree { 
graph [rankdir = "TB"];
pid3844 -> pid3168 [];
pid404 -> pid524 [];
pid2576 -> pid3364 [];
pid352 -> pid1552 [];
pid644 -> pid4824 [];
pid500 -> pid1088 [];
pid344 -> pid352 [];
pid4652 -> pid2612 [];
pid3824 -> pid3388 [];
pid500 -> pid784 [];
pid644 -> pid1972 [];
pid352 -> pid1328 [];
pid500 -> pid1716 [];
pid500 -> pid3644 [];
pid500 -> pid928 [];
pid500 -> pid4276 [];
pid500 -> pid896 [];
pid644 -> pid2000 [];
pid500 -> pid3656 [];
pid1400 -> pid2352 [];
pid2576 -> pid3884 [];
pid0 -> pid4 [];
pid500 -> pid3116 [];
pid1400 -> pid2696 [];
pid644 -> pid3404 [];
pid404 -> pid532 [];
pid344 -> pid404 [];
pid1488 -> pid2856 [];
pid500 -> pid1016 [];
pid636 -> pid4944 [];
pid644 -> pid1880 [];
pid500 -> pid1420 [];
pid500 -> pid1152 [];
pid644 -> pid4604 [];
pid500 -> pid864 [];
pid644 -> pid3336 [];
pid3136 -> pid4576 [];
pid500 -> pid712 [];
pid500 -> pid1052 [];
pid864 -> pid3780 [];
pid4768 -> pid4760 [];
pid500 -> pid2564 [];
pid396 -> pid472 [];
pid404 -> pid500 [];
pid500 -> pid2120 [];
pid500 -> pid1276 [];
pid3884 -> pid3920 [];
pid2576 -> pid2752 [];
pid636 -> pid3252 [];
pid472 -> pid3744 [];
pid500 -> pid1572 [];
pid500 -> pid1172 [];
pid1488 -> pid2556 [];
pid2576 -> pid1884 [];
pid3744 -> pid3824 [];
pid3884 -> pid3912 [];
pid472 -> pid3764 [];
pid1764 -> pid2632 [];
pid2576 -> pid4808 [];
pid500 -> pid2800 [];
pid500 -> pid1652 [];
pid3824 -> pid2576 [];
pid896 -> pid3716 [];
pid2576 -> pid3836 [];
pid2532 -> pid2736 [];
pid472 -> pid804 [];
pid500 -> pid1872 [];
pid500 -> pid2456 [];
pid3824 -> pid4888 [];
pid420 -> pid4636 [];
pid500 -> pid3104 [];
pid644 -> pid3436 [];
pid4 -> pid272 [];
pid1172 -> pid1312 [];
pid500 -> pid1688 [];
pid4104 -> pid3908 [];
pid500 -> pid2284 [];
pid644 -> pid3380 [];
pid3824 -> pid2980 [];
pid3824 -> pid660 [];
pid500 -> pid4132 [];
pid644 -> pid3612 [];
pid500 -> pid412 [];
pid1764 -> pid3368 [];
pid396 -> pid420 [];
pid500 -> pid300 [];
pid3824 -> pid3444 [];
pid4652 -> pid4104 [];
pid500 -> pid2900 [];
pid2576 -> pid344 [];
pid2576 -> pid5044 [];
pid500 -> pid644 [];
pid500 -> pid1304 [];
pid500 -> pid2992 [];
pid500 -> pid940 [];
pid500 -> pid1400 [];
pid500 -> pid1764 [];
pid3436 [label="3436 | dllhost.exe |exited\n2018-01-04 16:15:51 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid4132 [label="4132 | wmpnetwk.exe |running" shape="record" ];
pid3388 [label="3388 | StikyNot.exe |running" shape="record" ];
pid1972 [label="1972 | unsecapp.exe |running" shape="record" ];
pid4 [label="4 | System |running" shape="record" ];
pid2800 [label="2800 | msdtc.exe |running" shape="record" ];
pid420 [label="420 | csrss.exe |running" shape="record" ];
pid4604 [label="4604 | HelpPane.exe |running" shape="record" ];
pid1016 [label="1016 | svchost.exe |running" shape="record" ];
pid3764 [label="3764 | obommhdf.exe |exited\n2018-01-02 04:13:28 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid660 [label="660 | vmtoolsd.exe |running" shape="record" ];
pid3380 [label="3380 | dllhost.exe |exited\n2018-01-04 16:22:49 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid4944 [label="4944 | GoogleUpdate.e |exited\n2018-01-04 14:33:14 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid1052 [label="1052 | spoolsv.exe |running" shape="record" ];
pid3920 [label="3920 | GoogleCrashHan |exited\n2018-01-02 04:12:59 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid5044 [label="5044 | chrome.exe |running" shape="record" ];
pid272 [label="272 | smss.exe |running" shape="record" ];
pid2556 [label="2556 | GoogleCrashHan |running" shape="record" ];
pid2456 [label="2456 | dllhost.exe |exited\n2018-01-01 21:34:59 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid3908 [label="3908 | TRACERT.EXE |running" shape="record" ];
pid4636 [label="4636 | conhost.exe |running" shape="record" ];
pid1652 [label="1652 | VGAuthService. |running" shape="record" ];
pid472 [label="472 | winlogon.exe |running" shape="record" ];
pid500 [label="500 | services.exe |running" shape="record" ];
pid352 [label="352 | csrss.exe |running" shape="record" ];
pid3364 [label="3364 | chrome.exe |running" shape="record" ];
pid1872 [label="1872 | WmiApSrv.exe |exited\n2018-01-01 21:18:56 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid532 [label="532 | lsm.exe |running" shape="record" ];
pid4104 [label="4104 | svchost.exe |running" shape="record" ];
pid524 [label="524 | lsass.exe |running" shape="record" ];
pid3336 [label="3336 | dllhost.exe |exited\n2018-01-04 16:19:22 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid1764 [label="1764 | SearchIndexer. |running" shape="record" ];
pid1312 [label="1312 | winlogbeat.exe |running" shape="record" ];
pid3744 [label="3744 | userinit.exe |exited\n2018-01-02 04:13:27 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid3116 [label="3116 | GoogleUpdate.e |exited\n2018-01-04 14:33:14 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid3912 [label="3912 | GoogleCrashHan |exited\n2018-01-02 04:12:59 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid344 [label="344 | chrome.exe |running" shape="record" ];
pid2900 [label="2900 | VSSVC.exe |exited\n2018-01-01 21:38:00 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid2992 [label="2992 | VSSVC.exe |exited\n2018-01-01 21:13:40 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid2120 [label="2120 | dllhost.exe |exited\n2018-01-01 21:13:40 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid3716 [label="3716 | taskeng.exe |exited\n2018-01-02 04:17:59 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid412 [label="412 | sppsvc.exe |exited\n2018-01-01 21:17:37 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid1688 [label="1688 | vmtoolsd.exe |running" shape="record" ];
pid3884 [label="3884 | chrome.exe |running" shape="record" ];
pid4760 [label="4760 | AdobeARM.exe |exited\n2018-01-02 04:22:56 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid300 [label="300 | svchost.exe |running" shape="record" ];
pid1276 [label="1276 | VSSVC.exe |exited\n2018-01-02 04:12:36 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid3780 [label="3780 | dwm.exe |running" shape="record" ];
pid784 [label="784 | svchost.exe |running" shape="record" ];
pid712 [label="712 | svchost.exe |running" shape="record" ];
pid1400 [label="1400 | splunkd.exe |running" shape="record" ];
pid3656 [label="3656 | taskhost.exe |running" shape="record" ];
pid1152 [label="1152 | armsvc.exe |running" shape="record" ];
pid3644 [label="3644 | GoogleUpdate.e |exited\n2018-01-02 04:22:28 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid2284 [label="2284 | svchost.exe |running" shape="record" ];
pid2752 [label="2752 | chrome.exe |running" shape="record" ];
pid2696 [label="2696 | splunk-admon.e |exited\n2018-01-04 15:58:14 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid2632 [label="2632 | SearchProtocol |exited\n2018-01-02 04:14:10 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid4576 [label="4576 | javaw.exe |exited\n2018-01-04 16:21:19 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid644 [label="644 | svchost.exe |running" shape="record" ];
pid1716 [label="1716 | ManagementAgen |exited\n2018-01-01 21:40:37 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid3404 [label="3404 | dllhost.exe |exited\n2018-01-04 16:16:05 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid3104 [label="3104 | Defrag.exe |exited\n2018-01-04 14:22:19 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid1884 [label="1884 | chrome.exe |running" shape="record" ];
pid928 [label="928 | VSSVC.exe |exited\n2018-01-02 05:09:51 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid2352 [label="2352 | splunk-winevtl |running" shape="record" ];
pid404 [label="404 | wininit.exe |running" shape="record" ];
pid2000 [label="2000 | WmiPrvSE.exe |running" shape="record" ];
pid1880 [label="1880 | WmiPrvSE.exe |exited\n2018-01-02 04:13:27 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid3824 [label="3824 | explorer.exe |running" shape="record" ];
pid3612 [label="3612 | dllhost.exe |exited\n2018-01-02 04:13:02 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid4808 [label="4808 | chrome.exe |running" shape="record" ];
pid3368 [label="3368 | SearchFilterHo |exited\n2018-01-02 04:14:10 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid3252 [label="3252 | GoogleUpdate.e |exited\n2018-01-04 14:44:57 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid1172 [label="1172 | Graylog-collec |running" shape="record" ];
pid1420 [label="1420 | taskhost.exe |exited\n2018-01-02 04:14:38 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid4276 [label="4276 | svchost.exe |exited\n2018-01-02 05:12:51 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid4888 [label="4888 | notepad.exe |running" shape="record" ];
pid804 [label="804 | LogonUI.exe |exited\n2018-01-02 04:13:02 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid2576 [label="2576 | chrome.exe |running" shape="record" ];
pid896 [label="896 | svchost.exe |running" shape="record" ];
pid4824 [label="4824 | dllhost.exe |exited\n2018-01-04 14:50:57 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid2564 [label="2564 | TrustedInstall |exited\n2018-01-02 04:22:32 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid3168 [label="3168 | GoogleUpdate.e |exited\n2018-01-02 04:22:28 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid2736 [label="2736 | jusched.exe |running" shape="record" ];
pid3836 [label="3836 | chrome.exe |running" shape="record" ];
pid1088 [label="1088 | svchost.exe |running" shape="record" ];
pid2980 [label="2980 | notepad.exe |running" shape="record" ];
pid1552 [label="1552 | conhost.exe |running" shape="record" ];
pid1328 [label="1328 | conhost.exe |running" shape="record" ];
pid1572 [label="1572 | Sysmon.exe |running" shape="record" ];
pid940 [label="940 | svchost.exe |exited\n2018-01-02 04:15:36 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid864 [label="864 | svchost.exe |running" shape="record" ];
pid3444 [label="3444 | chrome.exe |exited\n2018-01-04 15:12:12 UTC+0000" shape="record"  style = "filled" fillcolor = "lightgray" ];
pid2612 [label="2612 | svchost.exe |running" shape="record" ];
pid2856 [label="2856 | GoogleCrashHan |running" shape="record" ];
pid1304 [label="1304 | svchost.exe |running" shape="record" ];
}

I am using windows 10

My guess is that you have a BOM in the beginning of your file. I don’t know how to remove it on Windows. Your text editor might have a setting for it. Otherwise you could try to copy-paste the text into another text editor than the one you are using.

Based on some quick experiments, I think Magjac has identified the problem.
If you are using notepad to create your files, do not save as UTF-8 with BOM

p.s. What editor did you use to create this file?
p.p.s. first I’ve heard of BOM, ugh

It may be reasonable to make the cgraph lexical processor more robust to these UTF-8 characters, that can probably be treated as whitespace. I wonder if there are any good articles on best practices to solve this problem.

Thank you everyone! I was able to generate the PNG by changing the encoding to UTF-8. The UTF-8 with BOM was the problem. U was struggling with that for days. So once again I appreciate it.

1 Like

You were so right bro thanks for the help.

1 Like

I was just using the notepad app on my computer. And yea when I changed the encoding to a regular UTF-8 that solved the problem

Thank you. As the other people above suggested the UTF-8 with BOM was the problem. I changed it to a regular UTF-8 and that worked.

Its normally just a matter of checking the first 3 bytes for “magic” values, this is what notepad++ does: notepad-plus-plus/Buffer.cpp at 9d69db9b1540500bf360383c2e5b28da67ebcf68 · notepad-plus-plus/notepad-plus-plus (github.com)

This is surprising as Graphviz actually handles UTF-8 BOMs. I’m guessing perhaps Notepad saved the original file in UTF-16.

I get this error: PS C:\Users\MarkDuncan\Terraform-Projects> terraform graph | dot -Tsvg > TerraformGraph20220930.svg
Error: : syntax error in line 1 near ‘digraph’

What could the problem be? The terraform.tfstate file is located in AWS S3 bucket. terraform.tfstate.backup file is local.

please include the input file. it seems that there is indeed something wrong with line 1 (or line 2)

The resulting file is empty. There is no text.

Not the resulting (output) file; we are interested in the input file

Which file would that be? Sorry but I am new to this function. If the state file is desired, then all I can access is the backup file. It has sensitive data in it. Here is the first few lines of the backup file:
{
“version”: 4,
“terraform_version”: “1.1.7”,
“serial”: 17,

The backup file is over 1100 lines long.

Can you supply the first 5 or so lines of output from terraform graph? (I’m not familiar with terraform, but I think we need to see what it is inputting to dot.)

The .dot file is 0 bytes in size. There are no characters in the file when you open it.

(I hope we are not talking past each other. It would be much easier if we were all in the same room.)
As I understand it, the command

terraform graph

produces no output. That would result in no input for dot.
The error message referencing digraph confuses me, I’m trying to recreate this on Windows, but no success yet.

This did not work:
terraform graph | dot -Tsvg > TerraformGraph20220930.dot

This:
terraform graph
and this produced an invalid file to view:
dot -Tsvg TerraformGraph20220930.dot > TerraformGraph20220930.svg

This:
terraform graph
and this worked:
dot -Tpng TerraformGraph20220930.dot -o TerraformGraph20220930.png

I am content with this.